summaryrefslogtreecommitdiff
path: root/032.py
blob: 095862513ce9f3b59e838bf3d38f14673b361eea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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