python chanllenge [10]

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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券