-
-
Save jorendorff/3a9b4c649f8e3fd72d7d2941852cdf44 to your computer and use it in GitHub Desktop.
There must be a better way to compute this...
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
import random | |
random.seed() | |
def flip(): | |
return random.choice([True, False]) | |
def run(): | |
b = flip() | |
n = 1 | |
while True: | |
(a, b) = (b, flip()) | |
n += 1 | |
if a and b: | |
return n | |
runs = 100000 | |
def count(): | |
counts = [0] * 100 | |
for i in xrange(0, runs): | |
n = run() | |
if n < len(counts): | |
counts[n] += 1 | |
return counts | |
counts = count() | |
for n in range(2,10): | |
print round(float(counts[n]) / runs * 2**n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment