38
4
The goal of a Rosetta Stone Challenge is to write solutions in as many languages as possible. Show off your programming multilingualism!
The Challenge
When people use the term "average," they generally mean the arithmetic mean, which is the sum of the numbers divided by the number of numbers. There are, however, many more meanings to the word "mean," including the harmonic mean, the geometric mean, the arithmetic mean, the quadratic mean, and the contraharmonic mean.
Your challenge is to write a program which inputs a list of numbers and outputs those 5 different means. Additionally, you are trying to write programs in as many languages as possible. You are allowed to use any sort of standard library function that your language has, since this is mostly a language showcase.
Input
Input will be a list of positive numbers.
1,2,3,4,5
1.7,17.3,3.14,24,2.718,1.618
8.6
3,123456
10.1381,29.8481,14.7754,9.3796,44.3052,22.2936,49.5572,4.5940,39.6013,0.9602
3,4,4,6.2,6.2,6.2
Output
Output will be the five means in the order listed above (harmonic, geometric, arithmetic, quadratic, contraharmonic). Conveniently, this is the same as increasing order.
2.18978,2.6052,3,3.31662,3.66667
3.01183,4.62179,8.41267,12.2341,17.7915
8.6,8.6,8.6,8.6,8.6
5.99985,608.579,61729.5,87296.6,123453.
5.95799,14.3041,22.5453,27.9395,34.6243
4.5551,4.74682,4.93333,5.10425,5.28108
There will be some reasonable leniency in I/O format, but I do want several decimal places of accuracy. Since I want floating-point output, you can assume floating-point input.
The Objective Winning Criterion
As for an objective winning criterion, here it is: Each language is a separate competition as to who can write the shortest entry, but the overall winner would be the person who wins the most of these sub-competitions. This means that a person who answers in many uncommon languages can gain an advantage. Code-golf is mostly a tiebreaker for when there is more than one solution in a language: the person with the shortest program gets credit for that language.
If there is a tie, the winner would be the person with the most second-place submissions (and so on).
Rules, Restrictions, and Notes
Your program can be written in any language that existed prior to September 2th, 2014. I will also have to rely on the community to validate some responses written in some of the more uncommon/esoteric languages, since I am unlikely to be able to test them.
Please keep all of your different submissions contained within a single answer.
Also, no shenanigans with basically the same answer in a slightly different language dialects. I will be the judge as to what submissions are different enough.
Current Leaderboard
This section will be periodically updated to show the number of languages and who is leading in each.
- Algoid (337) - Beta Decay
- APL (42) - algorithmshark
- Awk (78) - Dennis
- BBC BASIC (155) - Beta Decay
- C (136) - Dennis
- C++ (195) - Zeta
- C# (197) - Martin Büttner
- CJam (43) - Dennis
- Clojure (324) - Michael Easter
- Cobra (132) - Ourous
- CoffeeScript (155) - Martin Büttner
- Commodore BASIC (104) - Mark
- Common Lisp (183) - DLosc
- Erlang (401) - Mark
- Fortran (242) - Kyle Kanos
- Fortran 77 (286) - Beta Decay
- GNU bc (78) - Dennis
- GolfScript (83) - Dennis
- Groovy (157) - Michael Easter
- Haskell (140) - Zeta
- J (28) - algorithmshark
- Java (235) - Michael Easter
- JavaScript (ES6) (112) - Dennis
- JRuby (538) - Michael Easter
- Julia (79) - Martin Büttner
- Lua (113) - AndoDaan
- Mathematica (65) - Martin Büttner
- Matlab (63) - Martin Büttner
- Octave (68) - Dennis
- Openscript (849?) - COTO
- Pascal (172) - Mark
- Perl (76) - Grimy
- PHP (135) - Dennis
- POV-Ray 3.7 (304) - Mark
- Prolog (235) - DLosc
- Pyth (52) - Dennis
- Python 2 (96) - Dennis
- Python 3 (103) - DLosc
- Q (53) - algorithmshark
- Q'Nial (68) - algorithmshark
- QBasic (96) - DLosc
- R (91) - plannapus
- Ruby (118) - Martin Büttner
- Rust (469) - Vi.
- Scala (230) - Michael Easter
- T-SQL (122) - MickyT
- TI-Basic (85) - Ypnypn
- TypeScript (393) - rink.attendant.6
- VBA (Excel) (387) - Stretch Maniac
- wxMaxima (134) - Kyle Kanos
Current User Rankings
- Dennis (10)
- Martin Büttner (6)
- Michael Easter (5)
- Mark, DLosc, algorithmshark (4)
- Beta Decay (3)
- Zeta, Kyle Kanos (2)
- Ourous, AndoDaan, COTO, Grimy, plannapus, Vi., MickyT, Ypnypn, rink.attendant.6, Stretch Maniac (1)
(If I made a mistake in the above rankings, let me know and I'll fix it. Also, the tiebreaker has not been applied yet.)
When you say you're lenient on I/O, does that mean functions are allowed, too, or does everything have to be a program (as far as that notion makes sense in some languages)? – Martin Ender – 2014-09-02T19:26:31.770
You missed my favourite mean: the logarithmic mean
– Level River St – 2014-09-02T20:20:51.940(a-b)/ln(a/b)
. I'll admit that only today did I find out how it generalises to a sample set of more than two :-) http://en.wikipedia.org/wiki/Logarithmic_meanSomebody should really write the Perl code... (then I could plageri... be inspired to implement it in Befunge'98 with the 0"LREP"4( fingerprint)... (win/win)... – AndoDaan – 2014-09-03T02:55:04.627
I wonder if you should count ECMAScript 5 and ECMAScript separately. Any ES5 answer is bound to be much, much longer. – Dennis – 2014-09-03T05:40:03.050
It will be tricky to enforce "I do want several decimal places of accuracy". At the very least, consider requiring a sample run against the test data. – Michael Easter – 2014-09-03T10:43:43.763
1September 2th, eh? – amalloy – 2014-09-04T18:29:25.870
Would you accept an entry in Labview? Not sure how you define "short"... – Floris – 2014-09-04T19:52:54.117
1Also - when it comes to built in commands in Linux, do you consider
bc
,awk
etc to be "languages" or "commands" - so would the different ways to implement this from a shell be counted at different languages? – Floris – 2014-09-04T19:59:11.4972
@Floris If in doubt: http://meta.codegolf.stackexchange.com/a/2073/8478
– Martin Ender – 2014-09-07T13:38:34.827@Floris How would you measure the length of a Labview program? – Beta Decay – 2014-09-07T15:56:03.657
@BetaDecay - interesting question. I suppose you could look at the size of the binary file? – Floris – 2014-09-07T17:52:28.223