Skip to content

Instantly share code, notes, and snippets.

@mcvarer
Created October 19, 2020 21:37
Show Gist options
  • Save mcvarer/694933bb591799f470dbfd56d559358c to your computer and use it in GitHub Desktop.
Save mcvarer/694933bb591799f470dbfd56d559358c to your computer and use it in GitHub Desktop.
"""
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