Two mathematicians, Rex and Ralph, have an ongoing competition to stump each other. Ralph was impressed by the ingenuity of Rex's last attempt using clues involving prime numbers, but he thinks he's got an even better one for Rex. He tells Rex he's thinking of a 6-digit number.
"All of the digits are different. The digital sum matches the number formed by the last two digits in the number. The sum of the first two digits is the same as the sum of the last two digits."
"Take the sum of the number, the number rotated one to the left, the number rotated one to the right, the number with the first three and last three digits swapped, the number with the digit pairs rotated to the left, and the number with the digit pairs rotated to the right. The first and last digits of this sum match the last two digits of the number, in some order."
Ralph then asks, "If each of the three numbers formed by the digit pairs in the number is prime, then what is the number?"
Rex looks confused, and for a moment Ralph thinks he's finally gotten him. Then Rex smiles, scribbles a few things down on a pad of paper and then says,
"Very nice, Ralph!"
Rex then tells Ralph his number.
What did Rex say?
srce='1234567890';
idxs=combinator(10,6,'p');
digs=srce(idxs);
for i=1:length(idxs)
ns=digs(i,:);
n=str2double(ns);
digsum=sod(ns);
if ns(1)~='0'
if digsum==str2double(ns(5:6))
if sod(ns(1:2))==sod(ns(5:6))
n1=n;
n2=str2double([ns(2:6) ns(1)]);
n3=str2double([ns(6) ns(1:5)]);
n4=str2double([ns(4:6) ns(1:3)]);
n5=str2double([ns(3:6) ns(1:2)]);
n6=str2double([ns(5:6) ns(1:4)]);
tot=sum([n1,n2,n3,n4,n5,n6]);
tots=char(string(tot));
d1= tots(1);
d2= tots(end);
if d1==ns(5) && d2==ns(6) || ...
d1==ns(6) && d2==ns(5)
if isprime(str2double(ns(1:2))) && ...
isprime(str2double(ns(3:4))) && ...
isprime(str2double(ns(5:6)))
disp(n);
disp(' ')
disp(n1)
disp(n2)
disp(n3)
disp(n4)
disp(n5)
disp(n6)
disp(tot)
end
end
end
end
end
end
>> rexAndRalph
416723
416723
167234
341672
723416
672341
234167
2555553
The number is 416723. The numbers shown below it are the numbers asked for in the third paragraph and their total
|
Posted by Charlie
on 2023-11-08 13:20:02 |