defgetNext(a): a = str(a) last = a[0] last_n = 1 ret = [] for i inrange(1, len(a)): if a[i] == last: last_n += 1 else: ret += [str(last_n), last] last = a[i] last_n = 1 ret += [str(last_n), last] ret = int(''.join(ret)) return ret
start = 1
for i inrange(1, 31): ne = getNext(start) start = ne print i, len(str(ne))