Created
December 16, 2015 14:43
-
-
Save TimCastelijns/963bf87332c8cfce2b1c 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
s = '1321131112' | |
for n in xrange(0, 40): | |
chains = [] | |
chain = s[0] | |
prev = s[0] | |
for index, c in enumerate(s[1:], start=1): | |
if c == prev: | |
chain += c | |
else: | |
chains.append(chain) | |
chain = c | |
prev = c | |
if index == len(s[1:]): | |
chains.append(chain) | |
new_s = '' | |
for item in chains: | |
new_s += '{}{}'.format(len(item), item[0]) | |
s = new_s | |
print len(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment