r/dailyprogrammer • u/rya11111 3 1 • Feb 27 '12
[2/27/2012] Challenge #16 [intermediate]
Your task is to write a program that simulates a game of craps.
Use the program to calculate various features of the game:
for example, What is the most common roll or average rolls in a game or maximum roll? What is the average winning percentage? Or you can make your own questions.
edit: if anyone has any suggestions for the subreddit, kindly post it in the feedback thread posted a day before. It will be easier to assess. Thank you.
10
Upvotes
2
u/CeilingSpy Feb 27 '12
Perl:
I didn't do any statistics, but I'm sure someone can add onto this.
2
u/bigmell Feb 29 '12
first time usin given/when thx luxgladius, anxiously anticipating perl6 'in' operators this is similar. Also found a bug, you cant use goto's in a given/when loop. supposed to be fixed in 5.12. Got a bit verbose, sacrificed a bit for clarity. Works though. Pass ngames on the command line
1
u/luxgladius 0 0 Feb 27 '12 edited Feb 27 '12
Perl:
Output:
1
u/sylarisbest Feb 28 '12
C++ with statistics:
1
u/prophile Feb 28 '12
Done in Python.
1
u/rowenwand Feb 28 '12
Done in Java. Stats for distribution of rolls and nr. of wins/losses (with/without point, and all in percent and absolute numbers) I added some sub functions to make it is easy to implement more statistics on rolls and wins/losses.
1
u/Tyaedalis Feb 29 '12 edited Feb 29 '12
I spent my breaks at work typing this into my phone, so it could probably be better, but here's my solution in Python 2.7.2:
Example Output:
It seems to me that the win rate is too high. Where's my mistake?FIXED; logistical error.1
u/cooper6581 Feb 29 '12
[Python with stats] (http://pastebin.com/XQ3fsGLm)
Sample output:
1
u/[deleted] Feb 29 '12
Hopefully beautiful Ruby code: http://pastie.org/3490327
1
u/drb226 0 0 Mar 01 '12
Some fun with monads in Haskell: http://hpaste.org/64580
Example usage:
I didn't implement the statistics, but given a random number generator, you can run one game, and then pass the generator at the end of that to the next game. The writer monad keeps track of the log for each game; from there it's just a matter of crunching the numbers.
1
u/Haruhi_Suzumiya Mar 04 '12
http://ren.pastebay.org/310241
1
u/Should_I_say_this Jul 13 '12
This one was fun :). I just made the game, didn't bother with calculating averages or anything.