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.
How would you improve the following code?
I'm looking specifically for:
- performance optimizations
- ways to shorten the code
- more "pythonic" ways to write it
def is_palindrome(num):
return str(num) == str(num)[::-1]
def fn(n):
max_palindrome = 1
for x in range(n,1,-1):
if x * n < max_palindrome:
break
for y in range(n,x-1,-1):
if is_palindrome(x*y) and x*y > max_palindrome:
max_palindrome = x*y
elif x * y < max_palindrome:
break
return max_palindrome
print fn(999)
product
orcombination
orpermutation
is mentioned, i'd checkitertools
first \$\endgroup\$