All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Square Rearranger (Posted on 2023-12-06) Difficulty: 3 of 5
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.

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
soln | Comment 2 of 26 |
The solution is:
 A          B          C 
42005  50042  74162

A^2               B^2                C^2
1764420025   2504201764   5500002244
       
Method:
This was a difficult programming challenge as the data structures
for the search got very large, with commensurate execution times.

To start off, it is easy to prove that A, B, and C must be 
the same length, and that their squares must 
be of twice that length. This then requires that 
the range of A, B and C is, for example, 31627 to 99999, not
10000 to 99999,  where 31627 ~ sqrt(10^9) 

To speed things up, I used the idea of matching SODs to screen 
for candidate trios. Also, to buy speed, I arranged arrays in 
memory for all SOD(A) and SOD(A^2) and all Inventory(A), (A^2), 
where the inventory "inv" is just the number of digits, 0 
to 9. I also sorted-out candidate arrays for each possible 
SOD (e.g., making ~ 90 = max(SOD(A^2)) arrays in the 5 digit case,
since a 5 digit number squared may have an SOD ranging
approximately from 1 to 90. I also included a reverse index 
to the A available for each SOD(A^2). 

The steps were:
step 1 - check SOD(A&B) = SOD(C^2)
         then... if inv(A&B) = inv(C^2)
step 2 - check SOD(A&C) = SOD(B^2) 
         then... if inv(A&C) = inv(B^2)
step 3 - check SOD(B&C) = SOD(A^2)
         then... if inv(B&C) = inv(A^2)
         Success!

I ran the search (with custom codes) for the 2, 3, 4 and 5 digit 
possibilities. Code is here for 2, 3, 4, 5 digits.  
I didn't get a bite until 4 digits, but the sole 
4-digit successful trio was degenerate (non-distinct):
3386 9146 9146: 11464996 83649316, and thus incorrect. 

Programming 5 digits got hard: I could not make INV(S&B) 
with all A concatenated with all B because 10^5 x 10^5 = 10GBy
which leads to segmentation faults in addressing. So I traded 
speed for size and had to concatenate inventories on-the-fly.
The 5 digit case needed 30 hrs of a modest CPU's time. Fortunately
the solution popped out in a few hours with A being small compared
9999. Also for the 5 digit case A^2 would only store in the 
integer(kind=int64) of the ISO Fortran Environment. With these 
hurdles jumped, the solution was reached.  

At 5 digits I got the real hits - the solution above, 
and another, very nearby, but slightly larger successful trio:
42005 50420 74162 (1764420025 2542176400 5500002244)
where B changed from 50042 to 50420

I also got a degenerate one like the 4 digit one: 33860 91460
and a new degenerate one: 42005 42005 74162. 
and another degenerate trio:
42005 74162 42005...  Note - these solutions 
have the same inv's; they are just 
nearly anagrams in general.
inv(A^2)=
0:(2 or 4) 1:0 2:2 3:0 4:2 5:2 6:0 7:0 8:0 9:0

There are only four solutions for 5 digits, listed below.
(There are no solution for 1,2,3, or 4 digits) 

42005 50042 74162
42005 50420 74162
48681 63126 93879
50042 50420 74162

For 6 digits, each 5 digit solution x 10 also works. E.g: 
420050 500420 741620 is also a solution.

Edited on December 20, 2023, 4:55 am
  Posted by Steven Lord on 2023-12-18 19:33:16

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information