Created
March 9, 2014 07:15
-
-
Save maxattack/9444004 to your computer and use it in GitHub Desktop.
Two Envelopes
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/python | |
import random | |
nonSwitcherMoney = 0 | |
switcherMoney = 0 | |
def random_amount_of_money(): return 1 + 999 * random.random() | |
def coin_flip(): return random.random() > 0.5 | |
# do a million trials | |
for i in xrange(1000000): | |
# pick an amount in the smaller envelope, X | |
X = random_amount_of_money() | |
# randomly pick an envelope to give to the player | |
player_received_smaller = coin_flip() | |
if player_received_smaller: | |
nonSwitcherMoney += X | |
switcherMoney += 2.0 * X | |
else: | |
nonSwitcherMoney += 2.0 * X | |
switcherMoney += X | |
print "Non Switcher Money:", nonSwitcherMoney | |
print "Always-Switch Money:", switcherMoney |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment