Skip to content

Instantly share code, notes, and snippets.

@klen
Created March 26, 2014 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klen/9786088 to your computer and use it in GitHub Desktop.
Save klen/9786088 to your computer and use it in GitHub Desktop.
""" Project Euler problem #4. """
import itertools as it
def problem():
u""" Solve the problem.
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.
Answer: 906609
"""
return max([
x for x in [
a * b for a, b in it.product(range(999, 900, -1), repeat=2)]
if is_palindrome(x)
])
def is_palindrome(num):
""" Check for number is palindrome. """
num = str(num)
return num == num[::-1]
if __name__ == '__main__':
print problem()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment