Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
http://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.
# Copyright 2013, Alex Ausch
# Free to use under attribution license: http://creativecommons.org/licenses/by/2.0/ca/
def is_palindrome(num):
palindrome = str(num)
return palindrome == palindrome[::-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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment