Project Euler 62: Find the smallest cube for which exactly five permutations of its digits are cube
Problem Description
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.
Analysis
Run through the numbers cubing each one as we go and when we reach a 5 permutation set we save the smallest cube. We continue this process until we exceed the number of digits for the minimum cube, which assures an exact minimum for 5 permutations. Without this extra check this program would fail when checking other combinations by terminating too soon.
For example, a 6 set permutation would erroneously return 1426487591593 instead of the correct value, 1000600120008, which is smaller.
Project Euler 62 Solution
Runs < 0.040 seconds in Python 2.7.Use this link to get the Project Euler 62 Solution Python 2.7 source.
Afterthoughts
- The series of cube roots are: 5027 7061 7202 8288 8384
float('Inf')
is a Python invention for describing positive infinity. Works well for this program as arbitrarily setting to some big number may prove to be not big enough for larger values of d.
Discussion
No comments yet.