Created
October 4, 2011 18:00
-
-
Save kevinjqiu/1262327 to your computer and use it in GitHub Desktop.
empirically prove monty hall
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
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