aboutsummaryrefslogtreecommitdiff
path: root/2025
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2025-12-07 09:04:37 +0100
committerThomas Voss <mail@thomasvoss.com> 2025-12-07 09:04:37 +0100
commit7e7554af619355bdabcc08e10212a8947d9bf287 (patch)
tree6fd71052d56260dfc7dc65ac616e027b84f19794 /2025
parent4c7b413ed9082d51b2af7f1c3cb2251ee2b1a338 (diff)
Add 2025 day 7 solutionsHEADmaster
Diffstat (limited to '2025')
-rwxr-xr-x2025/07/puzzle-1.py23
-rwxr-xr-x2025/07/puzzle-2.py31
2 files changed, 54 insertions, 0 deletions
diff --git a/2025/07/puzzle-1.py b/2025/07/puzzle-1.py
new file mode 100755
index 0000000..0c30dfa
--- /dev/null
+++ b/2025/07/puzzle-1.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python3
+
+
+def main() -> None:
+ with open('input', 'r') as f:
+ grid = tuple(tuple(x.strip()) for x in f.readlines())
+
+ xs = set()
+ xs.add(grid[0].index('S'))
+ cnt = 0
+
+ for row in grid[1:]:
+ for i, ch in enumerate(row):
+ if ch == '^' and i in xs:
+ cnt += 1
+ xs.remove(i)
+ xs.add(i - 1)
+ xs.add(i + 1)
+
+ print(cnt)
+
+if __name__ == '__main__':
+ main()
diff --git a/2025/07/puzzle-2.py b/2025/07/puzzle-2.py
new file mode 100755
index 0000000..3695889
--- /dev/null
+++ b/2025/07/puzzle-2.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python3
+
+import collections
+import functools
+
+
+Pos = collections.namedtuple('Pos', ['x', 'y'])
+
+
+def main() -> None:
+ with open('input', 'r') as f:
+ grid = tuple(tuple(x.strip()) for x in f.readlines())
+
+ pos = Pos(grid[0].index('S'), 0)
+ print(npaths(grid, pos))
+
+
+@functools.cache
+def npaths(grid: list[list[str]], pos: Pos) -> int:
+ if pos.y == len(grid):
+ return 1
+ if grid[pos.y][pos.x] == '^':
+ return (
+ npaths(grid, Pos(pos.x - 1, pos.y))
+ + npaths(grid, Pos(pos.x + 1, pos.y))
+ )
+ return npaths(grid, Pos(pos.x, pos.y + 1))
+
+
+if __name__ == '__main__':
+ main()