José Miguel Hernandez

social media engineer

Roll the Dice!

posted on Tuesday, October 6th, 2009 at 10:52
screenshot of dice rolling app built in JavaScript

screenshot of dice rolling app built in JavaScript

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.

try demo


Bookmark and Share

Tags: , , , ,

One Response to “Roll the Dice!”

  1. I’m really loving your posts, please keep them comming, Thank You.

Leave a Reply

Entries (RSS) and Comments (RSS) old blog