Last active
August 29, 2015 14:22
-
-
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)
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 | |
# 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