Skip to content

Instantly share code, notes, and snippets.

@hyonschu
Last active August 29, 2015 14:03
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 hyonschu/f35030364bd82f3a44f8 to your computer and use it in GitHub Desktop.
Save hyonschu/f35030364bd82f3a44f8 to your computer and use it in GitHub Desktop.
def run(simulations=1000):
totalvalue = 0
env1a = []
env2a = []
env1 = 0
env2 = 0
for i in range(simulations):
envelopes = [random.randint(2,20)]
select = random.randint(0,1)
if select==1:
envelopes.append(envelopes[0]/2)
else:
envelopes.append(envelopes[0]*2)
# select = random.randint(0,1)
env1 += envelopes[0]
env1a.append(envelopes[0])
env2a.append(envelopes[1])
env2 += envelopes[1]
totalvalue += envelopes[select]
return totalvalue*1.0/simulations*1.0, totalvalue, env1, env2
"""
In [255]: run(100)
Out[255]: (8.52, 852, 1083, 1491)
In [256]: run(100)
Out[256]: (7.45, 745, 1054, 1208)
In [257]: run(100)
Out[257]: (7.93, 793, 1116, 1290)
In [258]: run(100)
Out[258]: (7.32, 732, 993, 1226)
In [259]: run(100)
Out[259]: (8.75, 875, 1195, 1450)
In [260]: run(100)
Out[260]: (8.59, 859, 1117, 1483)
In [261]: run(100)
Out[261]: (7.23, 723, 1016, 1182)
env2 (last number) is always higher, often significantly higher
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment