Project Euler: Problem 4

https://projecteuler.net/problem=4

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

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

Create empty list of products


In [1]:
products = []

Add the products of all 3-digit numbers to the list


In [2]:
for i in range(1, 1000):
    for n in range(1,1000):
        products.append(i * n)

Create empty list of palindromes


In [3]:
pals = []

Check if number is a palindrome, return list of palindromes


In [4]:
def check_for_palindromes(products):
    for number in products:
        if number == int(str(number)[::-1]):
            pals.append(number)
    return(pals)

Print maximum from list of palindromes


In [5]:
print(max(check_for_palindromes(products)))


906609

Success!


In [ ]:
# This cell will be used for grading, leave it at the end of the notebook.