-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path062.py
More file actions
29 lines (25 loc) · 650 Bytes
/
062.py
File metadata and controls
29 lines (25 loc) · 650 Bytes
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
#!/usr/bin/python
#first approach - takes ages
import itertools, math
def is_thirdpower(n):
if n%5 == 0 and n%125 != 0:
return False
root = n**(1/3.0)
return int(root+0.5)**3 == n
for i in xrange(1000,10000):
if i%100 == 0:
print i
else:
num = str(i*i*i) #generate cube
tot = [int(num)]
for perm in itertools.permutations(num): #this can (and should) be done more efficiently
if perm[0] != '0':
intperm = int(''.join(perm))
if is_thirdpower(intperm):
if not intperm in tot:
tot = [intperm] + tot
#print tot
if len(tot) == 5:
break
if len(tot) == 4:
print "Number found: {}".format(num)