Skip to content

Instantly share code, notes, and snippets.

@wetmore
Created August 20, 2013 02:08
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 wetmore/6276358 to your computer and use it in GitHub Desktop.
Save wetmore/6276358 to your computer and use it in GitHub Desktop.
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