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.
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:
itertools library, which provides functions that create iterators for efficient looping.itertools.combinations function, we generate all possible unique pairs of these $3$-digit numbers. Each pair will be used to calculate their product.is_palindrome that takes an integer n as input and returns a boolean indicating whether n is a palindrome. This is done by converting the number to a string and checking if it reads the same forwards and backwards.is_palindrome function.max function and print the result, which is the largest palindrome made from the product of two $3$-digit numbers.Running the above code leads to an answer of $906609$