Created
March 26, 2014 15:32
-
-
Save klen/9786088 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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