Skip to content

Instantly share code, notes, and snippets.

@falsetru
Created May 16, 2011 16:53
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 falsetru/974828 to your computer and use it in GitHub Desktop.
Save falsetru/974828 to your computer and use it in GitHub Desktop.
차,염소,염소
import random
def simul1():
rooms = [0, 0, 1]
random.shuffle(rooms)
i = random.randrange(3) # initial
while True:
j = random.randrange(3) # goat
if j != i and rooms[j] == 0:
break
k = ({0, 1, 2} - {i, j}).pop()
return rooms[k] == 1 # switch
tries = 100000
wins = sum(simul1() for i in range(tries))
print(float(wins) / tries)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment