r/dailyprogrammer • u/oskar_s • Aug 20 '12
[8/20/2012] Challenge #89 [easy] (Simple statistical functions)
For today's challenge, you should calculate some simple statistical values based on a list of values. Given this data set, write functions that will calculate:
Obviously, many programming languages and environments have standard functions for these (this problem is one of the few that is really easy to solve in Excel!), but you are not allowed to use those! The point of this problem is to write the functions yourself.
- Thanks to Cosmologicon for suggesting this problem at /r/dailyprogrammer_ideas!
32
Upvotes
14
u/oskar_s Aug 20 '12 edited Aug 21 '12
By the way, I just wanted to apologize about the dearth of problems this last week. It was just one of those weeks where all of us moderators turned out to be very busy with real-world stuff, so posting sort-of fell through the cracks. We will try to keep up a regular schedule, but we are just volunteers who do this for fun, so stuff like that is occasionally going to happen. We all feel super-bad about it, if that makes you guys feel better :)
Good luck with the problems!
2
u/5hassay Aug 20 '12
"The standard deviation" link directs to "The variance" link
2
u/[deleted] Aug 22 '12 edited Aug 22 '12
Beginner, java, took me about 45 minutes to figure out how to put data from a txt file into an array.
What i noticed is that the number of read lines is static, which is bad.
Couldn't find a solution for this at the moment tho (maybe another loop which counts the amount of lines in the text document before reading the actual lines?)
Another thing that I ignored in this case was packing the different actions into different methods and then call them in the main method, didn't quite figure out how to parse the variables between the methods, sorry...
Tips, corrections etc. would be appreciated.
Pastebin here
My Solution:
Sorry for the german variable names, but i'm german...
Durchschnitt means "mean value".
Varianz means "variance".
Standardabweichung means "standard deviation".
6
u/Aardig Aug 20 '12 edited Aug 20 '12
Python.
Beginner. If you have any comments/feedback, I'd love to hear it.
output
4
u/Sokend Aug 20 '12 edited Aug 20 '12
Ruby:
3
u/5outh 1 0 Aug 20 '12 edited Aug 20 '12
Haskell:
3
u/bschlief 0 0 Aug 20 '12 edited Aug 20 '12
Ruby. Thanks to the mods for such a fun environment. No apologies necessary for the dearth of problems.
3
u/oskar_stephens Aug 21 '12
Ruby:
3
u/m42a Aug 21 '12
C++11
2
u/5hassay Aug 20 '12 edited Aug 21 '12
C++ (I'm in the early stages of learning, so forgive me. Also, my limited knowledge left me without an easy way to test on the given data, but I did successfully test it on smaller data.)
EDIT: Removed some using and include statements I forgot to remove, and shed some of the light of mathematics thanks to the reminders of mennovf
2
u/skeeto -9 8 Aug 20 '12 edited Aug 20 '12
In Emacs Lisp. It's a little bulky since reading the data in isn't a simple function call.
Output:
2
u/Wegener Aug 21 '12 edited Aug 21 '12
In R. Kinda new to it, so if any fellow R'ers (or anyone else really) would like to provide criticism, please do.
Output:
2
u/[deleted] Aug 21 '12
Perl. Couldn't figure out how to call a subroutine in a subroutine and make it work right, it seems like it was double calling, or I messed up and had the variance subroutine modifying the @data array. I'm super new to this, so if anyone sees what I did, please let me know. Did get the right answer though :V
2
u/[deleted] Aug 21 '12
Java:
2
u/Fapper Aug 21 '12 edited Aug 21 '12
My shot at Ruby!:
Output:
2
u/[deleted] Aug 22 '12
Here's my offerings (with the file located in my pythonpath)
2
u/pivotallever Aug 22 '12 edited Aug 22 '12
Python
Clean
Scary
2
u/mordisko Aug 22 '12
Clean python 3 with data check:
Output:
2
u/ctdonath Aug 22 '12
Canonical C++:
Gah. Need to upgrade gcc & Visual Studio to c++11 capable versions. Want to use
2
u/Acurus_Cow Aug 22 '12 edited Aug 22 '12
Python
Beginner trying to write nicer code than I have done up until now. Also playing around with list comprehensions.
Any comments are welcome.
2
u/anhyzer_way Aug 23 '12
Javascript:
2
u/[deleted] Aug 23 '12
This one is really cute in J:
2
u/[deleted] Aug 23 '12
Java:
2
u/jkoers29 0 0 Dec 28 '12
}
1
u/Rapptz 0 0 Aug 20 '12
C++11 using gcc4.7
1
u/SlamminAtWork Aug 20 '12
Can anyone post the dataset at a different domain, or possibly paste them into a comment? Pastebin is blocked by my company's proxy.
Thanks :)
1
u/lawlrng 0 1 Aug 20 '12
Output:
1
u/EvanHahn Aug 20 '12
Brushing up on my C:
My output is:
1
u/EvanHahn Aug 20 '12
Taking advantage of a hack involving JavaScript's Array.join and CoffeeScript's "Everything is an Expression":
Output:
I love CoffeeScript.
1
u/howeyc Aug 20 '12
Common Lisp:
1
u/mau5turbator Aug 20 '12
With Python:
Result:
1
u/InvisibleUp Aug 20 '12
[C] It may not be pretty, but it works, and that's that.
1
u/SPxChairman 0 0 Aug 21 '12 edited Aug 21 '12
Python:
Output:
1
u/Erocs Aug 21 '12
Scala 2.9
1
u/[deleted] Aug 21 '12
Output
I used a running average in the mean calculation because I could.
1
u/stgcoder Aug 21 '12
Python.
result:
1
u/SwimmingPastaDevil 0 0 Aug 21 '12
Output:
1
u/kcoPkcoP Jan 09 '13
Java
1
u/ctangent Aug 20 '12
python:
1
u/[deleted] Aug 21 '12
[removed] — view removed comment