Do you remeber the Sci Amer Mathematical Recreations column?

The column was originally written by Martin Gardner, then picked up by A.K. Dewdney, and I believe now by Ian Stewart.

This was my second favorite column in the magazine growing up, after the Amateur Scientist column.

On Sunday, I was feeling lazy, so I browsed the web from my couch and came across a archive of some of these columns and similar material from old magazines. One that struck me was the concept of number palindromes. These are numbers that are identical when read forward or backway. As an example is 121

In one of these columns there was an algorithm that allows you to find such palindromes from any starting integer.

START:
    Let A = starting integer
    Let B = reverse of A
    Let SUM = A + B
    If SUM is not palindrome
        A = SUM
       GOTO START
    ELSE
       PRINT SUM

So if you start with 21
A = 21
B = 12
SUM = 33
33 is a palindrome

What surprised me is that when you start with most numbers you get a palindrome pretty quickly; however, 196 has not resulted in a palindrome ever after many thousands of interations of the above alogorithm. As @artg_dms likes to describe it this is a good nuero plasticity exercise…

Anyway here is a quick python implementation if you want to play with the idea.

import sys

def reverse(value):
    tmp = str(value)
    retVal = tmp[::-1]
    return int(retVal)

value = input("What number do you want to try? ")
a = int(value)
notpalindrome = True
while notpalindrome:
    b = reverse(a)
    sum = a+b
    if a == b:
        notpalindrome = False
    else:
        print(a, "+", b, "=", sum)
    a = sum
3 Likes