Last active
September 11, 2020 21:07
-
-
Save betaprojects/ae0f2bbf7818b0a8d118f4ced5fe43c0 to your computer and use it in GitHub Desktop.
Project Euler & HackerRank problem 4 solution: The largest palindrome product - solved using Python
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
def is_palindromic(n): n=str(n); return n==n[::-1] | |
dd = dict() | |
for i in range(101, 1000): | |
for j in range(121, 1000, (1 if i%11==0 else 11)): | |
p = i*j | |
if p >= 101101 and is_palindromic(p): dd[p]=1 | |
lst = sorted(list(dd), reverse=True) | |
K = int(input("Enter a number between 101101 and 999999? ")) | |
q = min(lst, key=lambda x:x>=K) | |
print ("the nearest palindrome less than", K, "is", q) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment