-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem 38.py
48 lines (35 loc) · 1.01 KB
/
Problem 38.py
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
44
45
46
47
48
from collections import Counter
class PanDigital(int):
dig = ''
iteration = 1
def map(self, x):
return str(self * x)
def concat(self, digits):
return self.dig + digits
@property
def can_continue(self):
return len(self.dig) < 10 and self.count
@property
def count(self):
return all(False for x in Counter(self.dig).values() if x > 1)
@property
def sorted(self):
return ''.join(map(str, sorted(map(int, self.dig))))
@property
def ispandig(self):
return self.sorted == '123456789'
def transform(self):
while self.can_continue:
self.dig = self.concat(self.map(self.iteration))
if self.ispandig:
return self.dig
self.iteration += 1
return None
@property
def value(self):
v = self.transform()
if v is not None:
return int(v)
return None
p = PanDigital
print(max(p(x).value for x in range(10000) if p(x).value))