Last active
December 24, 2015 00:59
-
-
Save aausch/6720461 to your computer and use it in GitHub Desktop.
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.
This file contains hidden or 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
# 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