The Experimentor

Experimenting ON Earth

Palindromes

Numbers such as 233332 are called palindromes. They have the property that they are same forward as backward. Interestingly enough if we start from any number and continuously reverse and add, it usually ends up in a palindrome.

For example we start with 7513:

7513+3157= 10670

10670+7601=18271

18271+17281=35552

35552+25553=61105

61105+50116=111221

111221+122111=233332

Thus we get a palindrome in six reverse and add operations.

Here is a simple python program to do the dirty reverse and add and give us the palindromes.

Notably, not every integer yields a palindrome this way. For example 196 does not.


Download the source

March 1, 2008 - Posted by asadujjaman | Python | | No Comments Yet

No comments yet.

Leave a comment