第10关地址:http://www.pythonchallenge.com/pc/return/bull.html
账号:huge 密码:file
页面提示 len(a[30])
点击大牛的位置,跳转到了http://www.pythonchallenge.com/pc/return/sequence.txt
a = [1, 11, 21, 1211, 111221,
也就是找规律,求len(a[30])是多少
规律是第二个数字是读第一个数字,如
1:1个1=11
11:2个1=21
21:1个2,2个1=1221
1211:1个1,1个2,2个1=111221
111221:3个1,2个2,1个1=312211
...以此类推得到a[30]并且计算长度
def deal_numNew(str_num): num = 1 new_list = [] if len(str_num) == 1: num = 1 new_list.append(str(num)) new_list.append(str_num[0]) else: for i in range(len(str_num)): if i+1==len(str_num): new_list.append(str(num)) new_list.append(str_num[i]) elif str_num[i+1] == str_num[i]: num += 1 else: new_list.append(str(num)) new_list.append(str_num[i]) num = 1 return ''.join(new_list) a = [1, 11, 21, 1211, 111221, 312211] str_num = "312211" for i in range(30): new_list = deal_numNew(str_num) a.append(new_list) str_num = a[-1] print(a[30]) print(len(a[30]))
得到 len(a[30]) = 5808
获得下一关地址:http://www.pythonchallenge.com/pc/return/5808.html