Back to Problems

Problem 4: Largest Palindrome Product

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

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

Solution Approach

The solution to this problem can quickly be found through the use of the itertools library in python

import itertools

numbers = range(100, 1000)  # 3-digit numbers
pairs = list(itertools.combinations(numbers, 2))

def is_palindrome(n: int) -> bool:
    s = str(n)
    return s == s[::-1]
  
palindromic_products = [x * y for x, y in pairs if is_palindrome(x * y)]
answer = max(palindromic_products)
print(answer)

Explained line by line:

Running the above code leads to an answer of $906609$