aboutsummaryrefslogtreecommitdiff
path: root/2023/04
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-12-20 08:07:26 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-12-20 08:07:26 +0100
commiteee14769b46a0dbf5f6765827b6daab333d259fc (patch)
tree9f10a051f1bb3125dc3f86239fc9a3de7f8c5e49 /2023/04
parentff03dafbae6f53027a1e79e1a60678afc31ebbdf (diff)
Add 2023 day 4 solutions
Diffstat (limited to '2023/04')
-rw-r--r--2023/04/puzzle-1.py14
-rw-r--r--2023/04/puzzle-2.py16
2 files changed, 30 insertions, 0 deletions
diff --git a/2023/04/puzzle-1.py b/2023/04/puzzle-1.py
new file mode 100644
index 0000000..8c221d8
--- /dev/null
+++ b/2023/04/puzzle-1.py
@@ -0,0 +1,14 @@
+def main() -> None:
+ acc = 0
+ with open("input", "r") as f:
+ while line := f.readline():
+ l, r = map(str.split, line.split('|'))
+ l = set(filter(str.isdigit, l))
+ r = set(filter(str.isdigit, r))
+ if s := l & r:
+ acc += 1 << (len(s) - 1)
+ print(acc)
+
+
+if __name__ == "__main__":
+ main() \ No newline at end of file
diff --git a/2023/04/puzzle-2.py b/2023/04/puzzle-2.py
new file mode 100644
index 0000000..8fdf4fd
--- /dev/null
+++ b/2023/04/puzzle-2.py
@@ -0,0 +1,16 @@
+def main() -> None:
+ with open("input", "r") as f:
+ lines = f.readlines()
+ xs = [1] * len(lines)
+ for i, line in enumerate(lines):
+ l, r = map(str.split, line.split('|'))
+ l = set(filter(str.isdigit, l))
+ r = set(filter(str.isdigit, r))
+ n = len(l & r)
+ for j in range(n):
+ xs[i + j + 1] += xs[i]
+ print(sum(xs))
+
+
+if __name__ == "__main__":
+ main() \ No newline at end of file