Find the smallest three distinct whole numbers A, B and C such that you can rearrange the digits of A and B to get C^2, the digits of A and C to get B^2, and the digits of B and C to get A^2.
**** Leading zeroes are not allowed.
I improved the algorithm. The 5 digit case takes 3 hr instead of
A, B, C are called i, j, k. The "inv" means the inventory; the
of the number of: 0's, 1's, ..., 9's in the number
"&" means combine the digits into a long list.
We explore i < j < k with loops:
step 1 - find SOD(i & j)
step 2 - use list of SOD(squares) to find k
step 3 - if (k.le.j) loop
step 4 - find SOD(i & k)
step 5 - if SOD(i&K) .ne. SOD(j^2) loop
step 6 - find SOD(j & k)
step 7 - if SOD(j&K) .ne. SOD(i^2) loop
step 8 - if .not. inv(i)+inv(j)=inv(k^2) loop
step 9 - if .not. inv(i)+inv(k)=inv(j^2) loop
step 10- if .not. inv(j)+inv(k)=inv(i^2) loop
To get here we did not loop, so we have an answer!
loop for more i, j, k
The first found solution below is the answer:
i.e., the smallest...
lord@rabbit 13382 % loo5a
cpu time = 3.3 min, A = 41800 out of 99999
cpu time = 4.3 min, A = 41900 out of 99999
cpu time = 5.3 min, A = 42000 out of 99999
--------- A, B, C, C^2, Inventory(C^2)
42005 50042 74162 5500002244
0:4 1:0 2:2 3:0 4:2 5:2 6:0 7:0 8:0 9:0
--------- A, B, C, C^2, Inventory(C^2)
42005 50420 74162 5500002244
0:4 1:0 2:2 3:0 4:2 5:2 6:0 7:0 8:0 9:0
cpu time = 6.3 min, A = 42100 out of 99999
cpu time = 7.3 min, A = 42200 out of 99999
cpu time = 8.3 min, A = 42300 out of 99999
.
.
.
cpu time = 0.8 min, A = 48500 out of 99999
cpu time = 1.6 min, A = 48600 out of 99999
--------- A, B, C, C^2, Inventory(C^2)
48681 63126 93879 8813266641
0:0 1:2 2:1 3:1 4:1 5:0 6:3 7:0 8:2 9:0
cpu time = 0.6 min, A = 49900 out of 99999
cpu time = 1.2 min, A = 50000 out of 99999
.
.
.
--------- A, B, C, C^2, Inventory(C^2)
50042 50420 74162 5500002244
0:4 1:0 2:2 3:0 4:2 5:2 6:0 7:0 8:0 9:0
cpu time = 2.0 min, A = 50100 out of 99999
cpu time between steps goes as (99999-i); when we get
near 99999 there are fewer j and k's to check.
There are no solutions for the 1,2,3 and 4 digit A, B, Cs.
All four 5 digit solutions are listed above, including the smallest.
6-digit solutions can be made from 10 x 5-digit solutions.
Edited on December 24, 2023, 12:27 am