summaryrefslogtreecommitdiff
path: root/3_2024.py
diff options
context:
space:
mode:
Diffstat (limited to '3_2024.py')
-rw-r--r--3_2024.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/3_2024.py b/3_2024.py
new file mode 100644
index 0000000..057044c
--- /dev/null
+++ b/3_2024.py
@@ -0,0 +1,23 @@
+from re import match
+import sys
+
+input = "data/3_2024.txt"
+data = open(input).read().strip()
+lines = data.split("\n")
+p1, p2, enabled = 0, 0, True
+
+sys.setrecursionlimit(10**6)
+for i in range(len(data)):
+ if data[i:].startswith("do()"):
+ enabled = True
+ if data[i:].startswith("don't()"):
+ enabled = False
+ instr = match(r"mul\((\d{1,3}),(\d{1,3})\)", data[i:])
+ if instr is not None:
+ x, y = int(instr.group(1)), int(instr.group(2))
+ p1 += x * y
+ if enabled:
+ p2 += x * y
+
+print(p1)
+print(p2)