We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 29df13f commit 2cffbf8Copy full SHA for 2cffbf8
2024/07/07.py
@@ -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
@@ -0,0 +1,9 @@
+190: 10 19
+3267: 81 40 27
+83: 17 5
+156: 15 6
+7290: 6 8 6 15
+161011: 16 10 13
+192: 17 8 14
+21037: 9 7 18 13
+292: 11 6 16 20
0 commit comments