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.
clearvars,clc
ct=0;
for n=5:10000
cube=n^3;
cset=unique(str2double(string(perms(num2str(cube)))));
cubes=[];
for i=1:length(cset)
if iscube(cset(i))
cubes(end+1)=cset(i);
end
end
if length(cubes)>2
disp(cubes)
ct=ct+1;
if ct>=20
break
end
end
end
function ic=iscube(x)
cr=round(x^(1/3));
if cr^3==x
ic=true;
else
ic=false;
end
end
did not weed out leading zeros, as the point where that was possible to check is buried in a nested type conversion. Some extra code could have checked the proposed solutions, but it's easy enough to check manually.
It's possible to find by looking:
125 512 125000 512000
125 512 125000 512000
1 1000 1000000
1331 1030301 1331000
1331 1030301 1331000
8 8000 8000000
10648 140608 10648000
27 27000 27000000
41063625 56623104 66430125
42875 54872 42875000 54872000
42875 54872 42875000 54872000
41063625 56623104 66430125
64 64000 64000000
41063625 56623104 66430125
91125 110592 91125000
103823 30080231 103823000
91125 110592 91125000 110592000
125 512 125000 512000 125000000 512000000
10648 140608 10648000 140608000
Operation terminated by user during str2double
The line
41063625 56623104 66430125
shows that 41063625 is the first such cube.
The three are respectively the cubes of 345, 384, and 405.
|
Posted by Charlie
on 2024-02-18 13:39:36 |