Skip to content

Instantly share code, notes, and snippets.

@kevinjqiu
Created October 4, 2011 18:00
Show Gist options
  • Save kevinjqiu/1262327 to your computer and use it in GitHub Desktop.
Save kevinjqiu/1262327 to your computer and use it in GitHub Desktop.
empirically prove monty hall
import random
import sys
def pick(switch):
doors = ['car', 'goat', 'goat']
random.shuffle(doors)
choices = zip(range(len(doors)), doors)
my_choice = random.choice(choices)
rest_choices = filter(lambda x: x!=my_choice, choices)
eliminate = filter(lambda x: x[1]!='car', rest_choices)[0]
if switch:
my_choice = filter(lambda x: x!=my_choice and x!=eliminate, choices)[0]
return my_choice[1] == 'car'
chances = int(sys.argv[1])
print len(filter(lambda x: x==True, [pick(False) for x in xrange(chances)]))
print len(filter(lambda x: x==True, [pick(True) for x in xrange(chances)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment