Last active
June 10, 2016 16:20
-
-
Save jrjames83/80c5a389b82a25638973485bdd98e363 to your computer and use it in GitHub Desktop.
Largest palindrome product (python euler4)
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
| #https://projecteuler.net/problem=4 | |
| #https://projecteuler.net/problem=4 | |
| def isPal(string): | |
| if len(string) <= 1: | |
| return True | |
| if list(string)[0] != list(string)[-1]: | |
| return False | |
| x = list(string) | |
| if x[0] == x[-1]: | |
| x.pop(0) | |
| x.pop(-1) | |
| return isPal(x) | |
| combos = [] | |
| for num in range(100,1000): | |
| for num1 in range(100,1000): | |
| combos.append((num, num1)) | |
| #products = [(tup[0] * tup[1]) for tup in combos] | |
| #print max([nbr for nbr in products if isPal(str(nbr))]) | |
| #Make it a 1 liner | |
| print max([nbr for nbr in [(tup[0] * tup[1]) for tup in combos] if isPal(str(nbr))]) | |
Author
jrjames83
commented
Jun 10, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment