The door to Prof. Adams
laboratory has one of those keypad
locks that requires entering five
digits to open. Unfortunately, he
has a hard time remembering the
combination, but he has figured
out a way to determine it.
The five
digits are all different, and he has
observed that the first two digits
form a perfect square, while the last
two digits form a smaller perfect
square. Also, the middle digit is the
smallest. If he arranges the five
digits to form all possible five-digit
integers (leading zeros allowed) and
adds all these numbers, the sum is
a palindrome, with each of its digits
a multiple of three.
What is the
combination?
clc
sqs=[4:9].^2;
for i=1:length(sqs)-1
last=num2str(sqs(i));
for j=i+1:length(sqs)
first=num2str(sqs(j));
m=char(min([first last]));
for mid='0':char(m-1)
n=[first mid last];
if isequal(sort(n),unique(n))
if isPalin(sum(str2num(perms(n))))
comb=[n];
disp([str2num(n) sum(str2num(perms(n)))])
end
end
end
end
end
finds all numbers fitting each criterion except for checking that each digit of the sum of the permutations of the digits is a multiple of 2. The candidates are
combination sum of
permutations
36025 4266624
81025 4266624
49236 6399936
Only the last row has the sum of permutations' digits all be multiples of 3, so the combination is 49236.
|
Posted by Charlie
on 2024-12-27 10:44:57 |