Skip to content

Instantly share code, notes, and snippets.

@hectorpefo
Created May 22, 2016 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hectorpefo/5c51b476405a8c5daf984bf48e1d38b2 to your computer and use it in GitHub Desktop.
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/
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