diff options
Diffstat (limited to '032.py')
| -rw-r--r-- | 032.py | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -0,0 +1,43 @@ + +from common import pandigital + +pandigital = pandigital(9).numbers(5) +pandigital.remove(1) + +def is_pandigital(a, b, c): + d = [0]*10 + while a > 0: + digit = a % 10 + if d[digit] > 0: + return False + d[digit] += 1 + a /= 10 + while b > 0: + digit = b % 10 + if d[digit] > 0: + return False + d[digit] += 1 + b /= 10 + while c > 0: + digit = c % 10 + if d[digit] > 0: + return False + d[digit] += 1 + c /= 10 + return d[1:] == [1]*9 + +products = set() + +for a in pandigital: + for b in pandigital: + c = a * b + if c in pandigital and is_pandigital(a, b, c): + #print str(a), "*", str(b), "=", str(c) + products.add(c) + +sum = 0 +for p in products: + sum += p + +print sum + |
