Created
July 24, 2015 12:54
-
-
Save erikbern/22c48c622dd9e160419c to your computer and use it in GitHub Desktop.
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
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