2 digit Palindrome describes a process by which most multi-digit numbers eventually become palindromes. The process being to repeatedly add a given number to the number formed when its digits are reversed.
For example: 152 -> 152+251=403 -> 403+304=707
I applied that process to a certain three digit number four times before I got a palindrome.
After the first and second additions, it was still a three digit number, and neither was a palindrome.
After the third addition it became a four digit number, but still not a palindrome.
And after the fourth addition the result was a four digit palindrome.
What number did I start with, assuming the first digit was smaller than the last?
using Mathematica code I found the following solutions
{192,483,867,1635,6996}
{280,362,625,1151,2662}
{290,382,665,1231,2552}
{291,483,867,1635,6996}
{390,483,867,1635,6996}
only the first one satisfies the final condition of the first digit being smaller than the last.
thus the solution is 192
The code I used is
IsPalin[x_]:=(
dgs=IntegerDigits[x];
rdgs=Reverse[dgs];
If[rdgs==dgs,Return[True],Return[False]];
);
RevAdd[x_]:=(
dgs=IntegerDigits[x];
rdgs=Reverse[dgs];
rx=FromDigits[rdgs];
Return[x+rx];
);
For[num=100,num<=999,++num,
n1=RevAdd[num];
n2=RevAdd[n1];
n3=RevAdd[n2];
n4=RevAdd[n3];
If[!IsPalin[num] && !IsPalin[n1] && !IsPalin[n2] && !IsPalin[n3] && IsPalin[n4] && Length[IntegerDigits[n1]]==3 && Length[IntegerDigits[n2]]==3 && Length[IntegerDigits[n3]]==4 && Length[IntegerDigits[n4]]==4,
Print[{num,n1,n2,n3,n4}];
];
];
|
Posted by Daniel
on 2009-11-27 16:31:45 |