Created
January 16, 2019 20:37
-
-
Save gavinsykes/8ebfa6d110cf99dd9c2cbda1d3537667 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
# A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99. | |
# | |
# Find the largest palindrome made from the product of two 3-digit numbers. | |
def largest_palindrome_product(n): | |
result = 0 | |
for i in range(n): | |
for j in range(n): | |
if(is_palindrome(i*j) and i*j > result): | |
result = i*j | |
return result | |
def is_palindrome(n): | |
if(str(n) == str(n)[::-1]): | |
return True | |
print largest_palindrome_product(1000) # Returns 906609 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment