`

Python Challenge (level 10)

阅读更多
URI: http://www.pythonchallenge.com/pc/return/bull.html
Username: huge; password: file
说明:

解题方法:
import itertools

def look_and_say (length):
    table = {
        ("1", "1", "1"): "31",
        ("1", "1"): "21",
        ("1", ): "11",
        ("2", "2", "2"): "32",
        ("2", "2"): "22",
        ("2", ): "12",
        ("3", "3", "3"): "33",
        ("3", "3"): "23",
        ("3", ): "13"
    }

    prec, result = "1", [1]

    for i in xrange(length - 1):
        prec = "".join(table[tuple(l)] for e, l in itertools.groupby(prec))
        result.append(int(prec))

    return result

print len(str(look_and_say(31)[30]))

过关答案:
5808
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics