Created
March 11, 2020 05:47
-
-
Save undergroundmonorail/73e1abf384f6060952f5b9943f84a476 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import random | |
switch_wins = 0 | |
switch_losses = 0 | |
no_switch_wins = 0 | |
no_switch_losses = 0 | |
for case in range(999999): | |
print(f'Test case {case}') | |
doors = random.choice([(1, 0, 0), (0, 1, 0), (0, 0, 1)]) | |
my_choice = random.randint(0, 2) | |
montys_choice = random.randint(0, 2) | |
while montys_choice == my_choice or doors[montys_choice]: | |
montys_choice = random.randint(0, 2) | |
remaining_door = [0, 1, 2] | |
remaining_door.remove(my_choice) | |
remaining_door.remove(montys_choice) | |
remaining_door = remaining_door[0] | |
no_switch_wins += doors[my_choice] | |
no_switch_losses += 1 - doors[my_choice] | |
switch_wins += doors[remaining_door] | |
switch_losses += 1 - doors[remaining_door] | |
print(f'------\n{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') | |
# ... | |
# Test case 999995 | |
# Test case 999996 | |
# Test case 999997 | |
# Test case 999998 | |
# ------ | |
# 666776 wins from switching | |
# 333223 losses from switching | |
# 333223 wins from not switching | |
# 666776 losses from not switching |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment