I have written down three different 5-digit perfect squares, which :
* between them use five different digits.
* each of the five digits is used a different number of times
* the five numbers of times being the same as the five digits of the perfect squares.
* no digit is used its own number of times.
* If you knew which digit I have used just once, you could deduce my three squares with certainty.
What are the three perfect squares?
Source:
a math puzzle posted to the SAS Discussion Forum (from New Scientist magazine).
clearvars,clc
sqs=[];
The number of occurrences of each unique digit is different and must add up to 15, and so can be only the digits 1 through 5, as each digit is the number of occurrences of another of the digits. That's also because zero occurrences is not allowed, as that wouldn't be one of the digits.
The restriction against other digits was not strictly necessary at the beginning, when filling in the sqs array (vector), but it does speed up the later processing, which would throw out other digits anyway.
clearvars,clc
sqs=[];
for i=100:316
sdig=char(string(i^2));
if max(sdig)-48<=5 && min(sdig)-48>0
sqs=[sqs i^2];
end
end
idxs=combinator(length(sqs),3,'c');
for i=1:length(idxs)
idx=idxs(i,:);
sqs3=sqs(idx);
digs=[char(string(sqs3))];
digs=reshape(digs,1,15);
udigs=unique(digs);
good=true; lgths=[];
if length(udigs)==5
for i=1:5
c=find(digs==udigs(i));
if length(c)==1
usedOnce=i;
end
lgths=[lgths length(c)];
if length(c)==i
good=false;
break
end
end
ulgths=unique(lgths);
if length(ulgths)==5
xxx=9;
end
if ~isequal(udigs-'0',unique(lgths))
good=false;
end
if good
disp([sqs3 usedOnce]);
end
end
end
The resulting possible sets of 3 squares are:
12321 12544 55225 3
12321 33124 34225 5
12321 44521 55225 3
12321 52441 55225 3
12544 34225 44521 3
12544 34225 52441 3
34225 44521 52441 3
Shown at the right on each line is the digit that appears only once in that set.
All except one of the sets has 3 as the non-repeating digit. Only the second set has 5 as the non-repeating digit. The sought set of three perfect squares is therefore:
12321 33124 34225
whose respective square roots are 111, 182, 185.
|
Posted by Charlie
on 2023-08-02 10:19:02 |