My son asks me “What do the numbers 26, 264, 307 and 836 all have in common?” After enjoying my puzzled look for a moment, he tells me all their squares are palindromes, but they’re not palindromes themselves.

Most palindrome squares are squares of palindromes, like (11 * 11) == 121, (121 * 121) == 14641, and (22 * 22) == 484. When the digits in palindrome number are small, so there is no carrying when you square, then the square is also a palindrome. But there are a few squares that are palindromes even with all the carrying. Like (307 * 307) == 94249.

Now I can’t let an 11 year-old show me up like that. I may not know all the squares to 1000, but I do know how to program, so I whipped up the following to find more of these squares.

# squares.py
# Python code to find squares that are palindromes.
__author__ = 'nealabq@gmail.com'
def is_palindrome( int_in_question) :
"""
True if int_in_question is an integer that is a
palindrome when written in base 10.
"""
# Change the number into a string and then a list.
as_list_of_chars = list( str( int_in_question))
# Copy the list and reverse it.
reversed_list_of_chars = list( as_list_of_chars)
reversed_list_of_chars.reverse( )
# True if the list of chars is palindromic.
return as_list_of_chars == reversed_list_of_chars
def print_palindrome_squares_up_to( limit) :
"""
Prints all the positive integers up to but not
including limit, where the integer's square is a
palindrome but the integer itself is not. Also
prints the square.
"""
for i in range( limit) :
if not is_palindrome( i) :
if is_palindrome( i * i) :
print( i, i * i)

Then I checked the first 100 million counting numbers. (This took a few minutes.)