Skip to content

Commit 2cffbf8

Browse files
committed
2024-12-07: part one: solution code and sample data
1 parent 29df13f commit 2cffbf8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

2024/07/07.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import itertools
2+
import sys
3+
4+
operators = {
5+
'*': int.__mul__,
6+
'+': int.__add__,
7+
}
8+
9+
result = 0
10+
for line in sys.stdin.read().splitlines():
11+
output, _, inputs = line.partition(': ')
12+
output, inputs = int(output), list(map(int, inputs.split()))
13+
procedures = itertools.product(operators.keys(), repeat=len(inputs) - 1)
14+
for procedure in procedures:
15+
evaluation = inputs[0]
16+
for input, operation in zip(inputs[1:], procedure):
17+
evaluation = operators[operation](evaluation, input)
18+
if evaluation == output:
19+
result += output
20+
break
21+
print(result)

2024/07/07.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
190: 10 19
2+
3267: 81 40 27
3+
83: 17 5
4+
156: 15 6
5+
7290: 6 8 6 15
6+
161011: 16 10 13
7+
192: 17 8 14
8+
21037: 9 7 18 13
9+
292: 11 6 16 20

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy