Fork me on GitHub

Find the largest palindrome made from the product of two 3-digit numbers

Problem Statement

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.

Find the largest palindrome made from the product of two 3-digit numbers.

Notes

This is a relatively simple list comprehension problem. Probably the only interesting aspect here is the way a number is checked for being a palindrome - ie. the test str(xy) == str(xy)[::-1]

For testing for palindrome we convert the number into a string. We subsequently reverse the string (the [::-1] slice). If both are same then the underlying number is a palindrome.

Solution

print max(x * y 
    for x in xrange(100,1000) 
        for y in xrange(100,1000) 
            if str(x*y) == str(x*y)[::-1])

Comments !

social