-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path32.py
More file actions
23 lines (18 loc) · 663 Bytes
/
32.py
File metadata and controls
23 lines (18 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import more_itertools
products = set()
digits = "123456789"
for p in more_itertools.distinct_permutations(digits):
for n in range(1, len(digits) - 1):
for left, middle, right in more_itertools.windowed_complete(p, n):
if not left:
continue
if not right:
continue
left = int("".join(left))
middle = int("".join(middle))
right = int("".join(right))
# print(f"{left} * {middle} == {right} ??")
if left * middle == right:
print(f"{left} * {middle} == {right}")
products.add(right)
print(sum(products))