Skip to content

Commit 0daaa3d

Browse files
committed
Add solution to 2025-12-07
1 parent d2b12f9 commit 0daaa3d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

2025/day07/solutions.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Solution by treating each splitter individually.
2+
3+
Here, we note that how many beams enter a splitter depends only on the
4+
ones above it, and immediately to its left/right. Moreover, once we find
5+
a splitter directly above a given splitter, we now that we can stop
6+
looking further up that column, since that splitter will block any beams
7+
from higher up.
8+
9+
By noting that no two splitters are ever horizontally adjacent, we can
10+
simplify the iteration logic a good deal.
11+
"""
12+
13+
with open("input") as f:
14+
ls = f.read().strip().split("\n")
15+
16+
splitters = [col for l in ls for col, x in enumerate(l) if x == "^"]
17+
entering = [1] + [0] * (len(splitters) - 1)
18+
19+
for i, si in enumerate(splitters):
20+
for j, sj in enumerate(splitters[:i][::-1]):
21+
if si == sj:
22+
break
23+
if abs(si - sj) == 1:
24+
entering[i] += entering[i - j - 1]
25+
26+
# Part 1
27+
print(sum(b > 0 for b in entering))
28+
29+
# Part 2
30+
print(sum(entering) + 1)

0 commit comments

Comments
 (0)