Created
February 13, 2015 00:42
-
-
Save lykkin/c20db3f6a1d128e40d46 to your computer and use it in GitHub Desktop.
sanity check for http://en.wikipedia.org/wiki/St._Petersburg_paradox
This file contains hidden or 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
from random import random | |
value = 0 | |
acc = 0 | |
payout = 2 | |
for n in xrange(1, 1000001): | |
for x in xrange(10000000): | |
if random() <= .5: | |
value += payout | |
payout = 2 | |
break | |
else: | |
payout *= 2 | |
acc *= n-1 | |
acc += float(value) | |
acc /= n | |
print acc/1000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment