Skip to content

Instantly share code, notes, and snippets.

@ycytai
Created October 2, 2021 14:23
Show Gist options
  • Save ycytai/92d84a4a98f3c20d1f01669192b793c5 to your computer and use it in GitHub Desktop.
Save ycytai/92d84a4a98f3c20d1f01669192b793c5 to your computer and use it in GitHub Desktop.
import random
doors = ['Goat', 'Car', 'Goat']
n = 1000
win = 0
lose = 0
for _ in range(n):
#-------------------------#
# shuffle and random pick #
#-------------------------#
random.shuffle(doors)
first_choice = random.randrange(3)
#--------------------------------#
# open a door with a goat behind #
#--------------------------------#
for idx, gift in enumerate(doors):
if idx != first_choice and gift == 'Goat':
open_door = idx
#----------------------------#
# change the original choice #
#----------------------------#
choices = [0, 1, 2]
choices.remove(first_choice)
choices.remove(open_door)
second_choice = choices[0]
#--------#
# result #
#--------#
if doors[second_choice] == 'Car':
win += 1
else:
lose += 1
print(f'Win:{win}, Lose:{lose}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment