Created
August 13, 2014 14:07
-
-
Save PRotondo/08393de54a597b56a767 to your computer and use it in GitHub Desktop.
look-and-say in binary
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
import itertools | |
def look_and_say(n) : | |
a = "0" | |
for i in xrange(n) : | |
b = "" | |
for c,l in itertools.groupby(a) : | |
b += bin(len(list(l)))[2:] + c | |
yield a | |
a = b | |
prev = 1 | |
for i,s in enumerate(look_and_say(100)) : | |
# a = int(s,2) | |
print float(len(s)) / float(prev) | |
prev = len(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment