All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Reverse, Add, Palindrome (Posted on 2009-11-27)
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?

 See The Solution Submitted by Brian Smith Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 Basic solution | Comment 2 of 4 |

The number sought is 192, and the sequence of numbers is:

192
483
867
1635
6996

DEFDBL A-Z
FOR n1 = 100 TO 789
d(1) = n1 \ 100
d(2) = (n1 \ 10) MOD 10
d(3) = n1 MOD 10
IF d(1) < d(3) THEN
n2 = n1 + d(3) * 100 + d(2) * 10 + d(1)
IF n2 < 1000 THEN
d(1) = n2 \ 100
d(2) = (n2 \ 10) MOD 10
d(3) = n2 MOD 10
n3 = n2 + d(3) * 100 + d(2) * 10 + d(1)

IF n3 < 1000 AND d(1) <> d(3) THEN
d(1) = n3 \ 100
d(2) = (n3 \ 10) MOD 10
d(3) = n3 MOD 10
n4 = n3 + d(3) * 100 + d(2) * 10 + d(1)

IF n4 >= 1000 AND d(1) <> d(3) THEN
d(1) = n4 \ 1000
d(2) = (n4 \ 100) MOD 10
d(3) = (n4 \ 10) MOD 10
d(4) = n4 MOD 10
n5 = n4 + d(4) * 1000 + d(3) * 100 + d(2) * 10 + d(1)

IF n5 < 10000 AND d(1) <> d(4) THEN
d(1) = n5 \ 1000
d(2) = (n5 \ 100) MOD 10
d(3) = (n5 \ 10) MOD 10
d(4) = n5 MOD 10
IF d(1) = d(4) AND d(2) = d(3) THEN
PRINT n1: PRINT n2: PRINT n3: PRINT n4: PRINT n5: PRINT
END IF
END IF

END IF

END IF

END IF
END IF
NEXT

 Posted by Charlie on 2009-11-27 18:26:08

 Search: Search body:
Forums (0)