-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem62.py
86 lines (56 loc) · 1.43 KB
/
Problem62.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Code by @AmirMotefaker
# projecteuler.net
# https://projecteuler.net/problem=62
# Cubic permutations
# Problem 62
# The cube, 41063625 (3453), can be permuted to produce two
# other cubes: 56623104 (3843) and 66430125 (4053). 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.
from itertools import permutations
import time
# time at the start of program
start = time.time()
# first list
list_1 = [1, 2, 3]
# second list
list_2 = [3, 2, 1]
# check if both the lists are same
print (list_1 == list_2)
print ("First List")
# lets print the permutations of first list
for i in permutations(list_1):
print (i)
print ("Second List")
# lets print the permutations of second list
for j in permutations(list_2):
print (j)
# list to store cubes
cubes = []
# iterator
i = 0
# while loop
while True:
# cube of the number
cube = sorted(list(str(i**3)))
# appending the cube to cubes list
cubes.append(cube)
# check if it occured 5 times
if cubes.count(cube) == 5:
# print the cube of the smallest such cube
print ((cubes.index(cube))**3)
break
i += 1
# i
i = 27
# str(i**3)
print (str(i**3))
# list(str(i**3))
print (list(str(i**3)))
# sorted(list(str(i**3)))
print (sorted(list(str(i**3))))
# time at the end of program
end = time.time()
# total time taken
print (end - start)