Solutions for the Python Challenge

Show possible solutions for: All levels; level: previous, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, next

Possible solution for level 10

URI:
http://www.pythonchallenge.com/pc/return/bull.html
Log-in data:
Username: huge; password: file
Comment:
Possible Solution:
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]))

(Download this source code.)

Code word for next challenge:
5808

By Holger Thölking, May 29th, 2007.