39 lines
962 B
Python
39 lines
962 B
Python
#!/usr/bin/env python
|
|
"""
|
|
Created on 25 Jul 2022
|
|
|
|
@author: David Doblas Jiménez
|
|
@email: daviddoji@pm.me
|
|
|
|
Solution for problem 062 of Project Euler
|
|
https://projecteuler.net/problem=62
|
|
"""
|
|
|
|
from collections import defaultdict
|
|
|
|
from utils import timeit
|
|
|
|
|
|
@timeit("Problem 062")
|
|
def compute():
|
|
"""
|
|
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.
|
|
"""
|
|
|
|
cubes = defaultdict(list)
|
|
for number in range(345, 10_000):
|
|
cube_str = "".join(sorted(list(str(number**3))))
|
|
cubes[cube_str].append(number**3)
|
|
if len(cubes[cube_str]) == 5:
|
|
return min(cubes[cube_str])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(f"Result for Problem 062: {compute()}")
|