-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path04.py
More file actions
25 lines (16 loc) · 658 Bytes
/
04.py
File metadata and controls
25 lines (16 loc) · 658 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# https://projecteuler.net/problem=4
# 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 itertools
import operator
three_digit_numbers = range(100, 1000)
products = (
(a * b, a, b)
for a, b in itertools.product(three_digit_numbers, three_digit_numbers)
)
def is_panindromic(n):
n = str(n)
return n == "".join(reversed(n))
palindromic_products = (p for p in products if is_panindromic(p[0]))
print(max(palindromic_products, key=operator.itemgetter(0)))
# >>> 906609