Skip to content

Instantly share code, notes, and snippets.

@toinetoine
Last active August 29, 2015 14: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 toinetoine/fe68f4b73944b73ae510 to your computer and use it in GitHub Desktop.
Save toinetoine/fe68f4b73944b73ae510 to your computer and use it in GitHub Desktop.
Runs 1 million "Let’s Make a Deal" games (demonstrating the Monty Hall Paradox)
import random
# number of games to play
num_games = 1000000
# keeps track of wins that occur when using
# the selection-change-after-reveal strategy
reselect_win_tally = 0
for i in range(num_games):
# there are three doors, and a random
# one has the car behind it
doors = [False, False, False]
cars_door = random.randrange(len(doors))
doors[cars_door] = True
# player selects a random door
selected_door = random.randrange(len(doors))
# if the selected door is not a car, then the
# strategy of changing the selection after the
# reveal will result in a win
if not doors[selected_door]:
reselect_win_tally+=1
print(str(reselect_win_tally) + " wins, " +
str(num_games - reselect_win_tally) + " losses")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment