The digits of 5^3, i.e. 125, can be rearranged to form 8^3, 512.
Find the smallest cube whose digits can be rearranged to form 2 other cubes.
The program finds 41063625.
41063625 = 345^3
56623104 = 384^3
66430125 = 405^3
-----------
Program Output:
3 [41063625, 56623104, 66430125]
-----------
from itertools import permutations
big = 1000
cubes = [c**3 for c in range(big)]
for c in cubes:
s = str(c)
cube_list = []
for perm in permutations(s):
if perm[0] == '0':
continue
jumble = int(''.join(perm))
if jumble < c:
continue
if jumble in cubes and jumble not in cube_list:
cube_list.append(jumble)
cube_list = sorted(list(set(cube_list)))
if len(cube_list) > 2:
print(len(cube_list), cube_list)
|
Posted by Larry
on 2024-02-18 12:23:55 |