-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path38.py
More file actions
24 lines (17 loc) · 646 Bytes
/
38.py
File metadata and controls
24 lines (17 loc) · 646 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
"""Project Euler Problem 38: https://projecteuler.net/problem=38"""
# Builds concatenated products and keeps the largest 1-9 pandigital result.
def solve() -> int:
"""Return the largest pandigital concatenated product."""
max_prod = 0
for i in range(99999, 1, -1):
prod = ""
for j in range(1, 10):
prod += str(i * j)
if len(prod) > 9:
break
if len(prod) == 9:
sorted_prod = sorted(prod, key=int)
if "".join(sorted_prod) == "123456789":
max_prod = max(int(prod), max_prod)
return max_prod
print(solve())