Skip to content

Instantly share code, notes, and snippets.

@bembu
Last active February 15, 2016 17:37
Show Gist options
  • Save bembu/7ff5afcd374e3b948358 to your computer and use it in GitHub Desktop.
Save bembu/7ff5afcd374e3b948358 to your computer and use it in GitHub Desktop.
Monty Hall Proof
# A quick test to prove https://en.wikipedia.org/wiki/Monty_Hall_problem
import random
ITERATIONS = 100000
DOORS = ["goat", "goat", "tesla"]
j = 0
for i in range (0, ITERATIONS):
shuffled_list = DOORS[:] # copy a list
random.shuffle(shuffled_list) # shuffle our copy
guess = shuffled_list.pop() # take a guess
shuffled_list.remove("goat") # the host shows where the other goat is hiding
if (shuffled_list[0] == "goat"): # two choices left, a goat and a ferrari
j += 1
print("You got {} goats in {} games by always changing the door".format(j, ITERATIONS))
print("The chance for a lovely goat was {0:.1f} %".format((float(j)/ITERATIONS)*100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment