Skip to content

Instantly share code, notes, and snippets.

@TimCastelijns
Created December 16, 2015 15:26
Show Gist options
  • Save TimCastelijns/c8df4a627c8d586c60ea to your computer and use it in GitHub Desktop.
Save TimCastelijns/c8df4a627c8d586c60ea to your computer and use it in GitHub Desktop.
s = '1321131112'
for n in xrange(0, 50):
chains = []
chain = s[0]
prev = s[0]
part = s[1:]
for index, c in enumerate(part, start=1):
if c == prev:
chain += c
else:
chains.append(chain)
chain = c
prev = c
if index == len(part):
chains.append(chain)
s = ''.join(['{}{}'.format(len(item), item[0]) for item in chains])
print 'done loop', n
print len(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment