gist: https://gist.github.com/genesislive/5106789
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
__author__ = 'Genesislive'
# http://www.pythonchallenge.com/pc/return/bull.html
# username: huge password:file
# a = [1, 11, 21, 1211, 111221,
# Look-and-say sequence
a = ['1']
sequence = '1'
for i in range(0, 30):
begin = ptr = 0
end = len(sequence)
next_seq = []
while ptr < end:
if sequence[ptr] != sequence[begin]:
next_seq.append(str(ptr - begin) + sequence[begin]) # num char
begin = ptr
ptr += 1 # next char
next_seq.append(str(ptr - begin) + sequence[begin]) # last char
sequence = ''.join(next_seq)
a.append(sequence)
print len(a[-1])