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.
def product_gen(num):
x = num
y = num - 1
while num < 2:
yield x * y
product_gen(2)
<generator object product_gen at 0x0000000003F5C1B0>
num1 = 999
num2 = 999
prod = None
prod_str = None
reverse_str = None
is_palindrome = False
maxpal = 0
while num1 > 2 and is_palindrome == False:
prod = num1 * num2
prod_str = str(prod)
reverse_str = prod_str[::-1]
if prod_str == reverse_str:
is_palindrome = True
if num2 == 99:
num2 = 999
num1 -= 1
else:
num2 -= 1
print prod
580085
def is_palindrome(num):
return int(str(num)[::-1]) == num
high_pal = 0
prod = None
for x in range(999, 99, -1):
for y in range(x, 99, -1):
prod = x * y
if is_palindrome(prod) and prod > high_pal:
high_pal = prod
print high_pal
906609