-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp62.py
executable file
·45 lines (40 loc) · 969 Bytes
/
p62.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
import euler_tools as et
def cp():
i = 12
cd = {}
smallest = {}
while True:
cubes = cubes_of_length(i)
for c in cubes:
split = split_string(c)
if cd.has_key(split):
cd[split] += 1
else:
cd[split] = 1
smallest[split] = c
for k, v in cd.iteritems():
if v == 5:
return smallest[k]
i += 1
def split_string(string):
chars = sorted(string)
i = 0
ret = []
while i < len(chars):
count = chars.count(chars[i])
ret.append((chars[i], count))
i += count
return tuple(ret)
def cubes_of_length(length):
i = 2
cubes = list()
max_val = int('9' * length)
min_val = int('9' * (length - 1))
while True:
val = i**3
if val > max_val:
break
if val > min_val:
cubes.append(str(val))
i += 1
return cubes