From 95341b61b030c9e1290f3b326cb7ec584f543aea Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sun, 31 Aug 2014 20:21:45 +0200 Subject: moved files to higher directory after split to new repository --- 032.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 032.py (limited to '032.py') diff --git a/032.py b/032.py new file mode 100644 index 0000000..0958625 --- /dev/null +++ b/032.py @@ -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 + -- cgit v1.2.3