blob: bc43644fc3df92812352a3288767a558d6b0ca52 (
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
|
def is_pandigital(x):
digits = 10*[0]
while x > 0:
digit = x % 10
if digit == 0:
return False
digits[digit] += 1
x /= 10
for i in range(1, 10):
if digits[i] != 1:
return False
return True
def pandigital(x):
result = str(x * 1)
count = 1
while len(result) < 9:
count += 1
result += str(x * count)
if len(result) > 9:
return 0
if is_pandigital(int(result)):
return int(result)
return 0
max_pd = 0
for i in xrange(9876):
p = pandigital(i)
if p > max_pd:
max_pd = p
i += 1
print max_pd
|