Last active
February 15, 2016 17:37
-
-
Save bembu/7ff5afcd374e3b948358 to your computer and use it in GitHub Desktop.
Monty Hall Proof
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
# 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