Created
May 22, 2016 17:22
-
-
Save hectorpefo/5c51b476405a8c5daf984bf48e1d38b2 to your computer and use it in GitHub Desktop.
Monte Carlo simulation of the riddler on fivethirtyeight.com http://fivethirtyeight.com/features/can-you-slay-the-puzzle-of-the-monsters-gems/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
num_trials = 100000 | |
total_ones = 0 | |
for dummy in range(1,num_trials): | |
missing = [1,1,1] | |
while not (missing == [0,0,0]): | |
gem = [0,0,0,1,1,2][random.randint(0,5)] | |
missing[gem] = 0 | |
if gem == 0: total_ones += 1 | |
print ("Result is ",total_ones/num_trials) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment