[Level 10]
Title: what are you looking at?
len(a[30]) = ?
除此之外,源码中没其他提示,图片牛的区域可点击,进去的网页显示a = [1, 11, 21, 1211, 111221,找到规律,再求出len(a[30])
即可。
import re
e = '1'
a = [e]
for i in range(30):
temp = ''
while e:
x = e[0]
c = re.match('{0}+'.format(x),e).end()
temp += str(c) + x
e = e[c:]
e = temp
a.append(e)
print(len(a[30]))#len(e)
21表示2个1(11),1211表示1个2,1个1(21)略坑。最终答案是5808,[Level 11]
Python Challenge Wiki
按此规律产生的字符串仅含有1、2和3三种字符,由此,产生字符串的方法也更多样了。如:
a = '1'
for i in range(30):
a = ''.join(map(lambda x: repr(len(x))+x[0], re.findall('(1+|2+|3+)', a)))
print(len(a))
或者`a = ''.join([str(len(i+j))+i for i,j in re.findall(r'(\d)(\1*)', a)])`
####[More](http://wiki.pythonchallenge.com/index.php?title=Level10:Main_Page)