Problem definition: A man walks into a pub and sees a jar full of dollar bills. The label says “Roll a 1,2,5,5,6 to win the pot”. The man has had a few drinks and doesn’t trust his napkin math. How many rolls will it take to win the money in the jar?
Solution: Write a script that rolls the dice thousands of times looking for a specific number of each die in any order, tracking the number of rolls and wins. Divide the number of rolls by the number of wins to calculate an average to hit the winning roll. In this case, I found that the average eventually tends toward 60, but individual results can frequently end up as high as 200 and as low as 8.
Implementation: HTML, CSS, JavaScript, Mootools 1.2.3.
