aboutsummaryrefslogtreecommitdiff
path: root/2023/04/puzzle-2.py
diff options
context:
space:
mode:
Diffstat (limited to '2023/04/puzzle-2.py')
-rw-r--r--2023/04/puzzle-2.py16
1 files changed, 16 insertions, 0 deletions
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