Skip to content

Instantly share code, notes, and snippets.

@erikbern
Created July 24, 2015 12:54
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 erikbern/22c48c622dd9e160419c to your computer and use it in GitHub Desktop.
Save erikbern/22c48c622dd9e160419c to your computer and use it in GitHub Desktop.
def coin():
while True:
yield random.randint(0, 1)
def dice_optimal():
x, y, z = 0, 1, 1
for c in coin():
x, y, z = x+c*z, y+c*z, 2*z
a, b = x*6//z, y*6//z
if a == b:
yield a
x, y = x*6-z*a, y*6-z*b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment