vendredi 15 octobre 2010

Euler #38

#!/usr/bin/env python

from libeuler import is_pandigital

def concatenated_product(n, l):
    return reduce(lambda x, y: str(x) + str(y), map(lambda x: x*n, l), '')

if __name__ == '__main__':
    r = []
    n = 1
    m = 9
    while True:
        p = concatenated_product(n, range(1, m+1))
        print "%d -> %s" % (n, p), range(1, m+1)
        if len(p) > 9:
            m -= 1
            if m < 2:
                break
            continue
        if is_pandigital(int(p)):
            r += [int(p)]
        n += 1
    print max(r)

Aucun commentaire:

Enregistrer un commentaire