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.


In [6]:
def pal(x): #function pal determines if the number is the same front and back
    return x==x[::-1]

a=0
for i in range(999,100,-1): #two for loops to iterate from 999 to 101, we want largest numbers
    for j in range(999,100,-1):
        num=i*j #multiply these two numbers
        if pal(str(num)) and num>a: #determines if the number, as a string, is the same front and back, then checks to see if it is greater than the value we're printing
            a=num #resets the value of a for every true instance of if statement
print(a)


906609

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