美文网首页
python chanllenge [10]

python chanllenge [10]

作者: nummycode | 来源:发表于2017-04-01 15:11 被阅读15次

solution:

def next(arr):
    start = arr[0]
    count = 1
    res = ""
    for index, ele in enumerate(arr):
        if index == 0:
            continue
        if arr[index] == start:
            count += 1
        else:
            res = res + str(count) + start
            start = arr[index]
            count = 1
    res = res + str(count) + start
    return res

arr = ['1']
for i in range(31):
        arr.append(next(arr[-1]))
print len(arr[30])

answer:5808

相关文章

网友评论

      本文标题:python chanllenge [10]

      本文链接:https://www.haomeiwen.com/subject/wrviottx.html