Created
October 19, 2020 21:37
-
-
Save mcvarer/694933bb591799f470dbfd56d559358c 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 × 99. | |
Find the largest palindrome made from the product of two 3-digit numbers. | |
""" | |
import numpy as np | |
def rev(num): | |
return int(num != 0) and ((num % 10) * (10 ** int(np.math.log(num, 10))) + rev(num // 10)) | |
def palindromicNumber(): | |
bigList = [] | |
for i in range(999, 100, -1): | |
for j in range(999, 100, -1): | |
x = i * j | |
if x == rev(x): | |
bigList.append(x) | |
return np.max(bigList) | |
print("largest palindrome made from the product of two 3-digit number = {}".format(palindromicNumber())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment