-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp062.py
More file actions
executable file
·47 lines (38 loc) · 1.26 KB
/
p062.py
File metadata and controls
executable file
·47 lines (38 loc) · 1.26 KB
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
#The cube, 41063625 (345^3), can be permuted to produce two other cubes: 56623104 (384^3) and 66430125 (405^3). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube.
#
#Find the smallest cube for which exactly five permutations of its digits are cube.
import logging
def Digits(a):
da = []
while (a):
da.append(a%10)
a = a//10
da.sort()
return da
def IsPermute(a,b):
return Digits(a) == Digits(b)
def main(args):
cubes = []
m = 10000
for n in range(m):
cubes.append(n*n*n)
pcube = {}
for i in range(m-1):
for j in range(i+1, m):
ci = cubes[i]
cj = cubes[j]
if (cj > ci*10): break
if (IsPermute(cubes[i], cubes[j])):
if (ci in pcube):
pcube[ci].append(cj)
if (len(pcube[ci])>3):
logging.info("answer: {}".format(ci))
logging.debug((ci, pcube[ci]))
return 0
else:
pcube[ci] = [cj]
logging.debug(pcube[(345, 41063625)])
for ci in list(pcube.keys()):
cj = pcube[ci]
if (len(cj)>2):
logging.debug((ci, cj))