Created
August 20, 2013 02:08
-
-
Save wetmore/6276358 to your computer and use it in GitHub Desktop.
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 randint | |
def run(goal, runs): | |
total = 0 | |
for x in xrange(runs): | |
sequence = [] | |
for i in xrange(3): | |
sequence.append(randint(0,1)) | |
while sequence[-3:] != goal: | |
sequence.append(randint(0,1)) | |
total += len(sequence) | |
return total / runs | |
print run([1, 0, 1], 1000000) | |
print run([0, 1, 1], 1000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment