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 started with a brute force program to check values for A,B,C up to 1000 but it was very slow on my system using Python.
My next thought is to build up a dictionary where the keys are the integers, say, N, and each value is a list of sets; each set has two elements; the elements are all ways of splitting the digits of N^2 to form two numbers. Consider 16^2 = 256, for example. Its dictionary entry would be:
{16: [{2, 56}, {2, 65}, {5, 26}, {5, 62}, {6, 25}, {6, 25}]}
The search to find the solution would be first generate these entries, not trivial for larger N.
And then to check each element of each 2-element set, {5, 26} for example to see if the other 2 members of the possible triplet are present elsewhere in the dictionary; ie a success would look like:
{5: [ ...., {16,26}, .... ] }
{26: [ ...., {5,16}, .... ] }
(sets because {a,b} is the same as {b,a})
Python uses curly braces {} both to signify a dictionary and a set.
I think this would be faster than brute force; but I haven't thought this part through fully.
|
Posted by Larry
on 2023-12-06 19:01:37 |