project-euler/062_cubic_permutations.py

32 lines
720 B
Python

#!/usr/bin/env python3
def cube(x):
i=3
lim=100
while True:
cubes=[]
while i**3<lim:
cubes.append(i**3)
i+=1
lim*=10
perm={}
ans=[]
ans_route={}
for j in cubes:
a="".join(sorted(str(j)))
try:
perm[a][0]+=1
if perm[a][0]==x:
ans.append(perm[a][1])
ans_route[perm[a][1]]=a
except:
perm[a]=[1,j]
if len(ans)>0:
for i in sorted(ans):
if perm[ans_route[i]][0]==x:
return i
if __name__ == '__main__':
print(cube(5))