Last active
September 17, 2017 06:45
-
-
Save carl-mastrangelo/c2810bff8c7f3907b8ab6727ce2548d1 to your computer and use it in GitHub Desktop.
expected value
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 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