Skip to content

Instantly share code, notes, and snippets.

@carl-mastrangelo
Last active September 17, 2017 06:45
Show Gist options
  • Save carl-mastrangelo/c2810bff8c7f3907b8ab6727ce2548d1 to your computer and use it in GitHub Desktop.
Save carl-mastrangelo/c2810bff8c7f3907b8ab6727ce2548d1 to your computer and use it in GitHub Desktop.
expected value
import random
import pprint
def run(tries):
count = 0
for i in range(tries):
if random.randrange(1<<count) <= 0:
count += 1
return count
for s in range(1, 100):
count = 0
runs = 100000
for i in range(runs):
runcount = run(s)
count += runcount
print s, count * 1.0 / runs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment