Skip to content

Instantly share code, notes, and snippets.

@undergroundmonorail
Created March 11, 2020 05:38
Show Gist options
  • Save undergroundmonorail/ba63411db91345eba0c57819b4d8ca8e to your computer and use it in GitHub Desktop.
Save undergroundmonorail/ba63411db91345eba0c57819b4d8ca8e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
switch_wins = 0
switch_losses = 0
no_switch_wins = 0
no_switch_losses = 0
# 1 is a car, 0 is a goat
for doors in [(1, 0, 0),
(0, 1, 0),
(0, 0, 1)]:
# number of the door with the car
car_door = doors.index(1)
for my_choice in range(3):
# these are the doors that monty is allowed to pick from
montys_doors = [0, 1, 2]
# monty can't pick the same door as you
montys_doors.remove(my_choice)
# monty can't pick the door with the car
if car_door in montys_doors:
montys_doors.remove(car_door)
for montys_choice in montys_doors:
remaining_door = [0, 1, 2]
remaining_door.remove(my_choice)
remaining_door.remove(montys_choice)
remaining_door = remaining_door[0]
# i will explain this part in the fedi post
no_switch_wins += doors[my_choice] / float(len(montys_doors))
no_switch_losses += (1 - doors[my_choice]) / float(len(montys_doors))
switch_wins += doors[remaining_door] / float(len(montys_doors))
switch_losses += (1 - doors[remaining_door]) / float(len(montys_doors))
print(f'{switch_wins} wins from switching\n{switch_losses} losses from switching\n{no_switch_wins} wins from not switching\n{no_switch_losses} losses from not switching')
# 6.0 wins from switching
# 3.0 losses from switching
# 3.0 wins from not switching
# 6.0 losses from not switching
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment