Skip to content

Instantly share code, notes, and snippets.

@TimCastelijns
Created December 16, 2015 14:43
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 TimCastelijns/963bf87332c8cfce2b1c to your computer and use it in GitHub Desktop.
Save TimCastelijns/963bf87332c8cfce2b1c to your computer and use it in GitHub Desktop.
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