Skip to content

Commit 4c883ea

Browse files
committed
Add day07, 2025
1 parent e48bc78 commit 4c883ea

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

2025/day07/solution.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from functools import cache
2+
3+
with open("input") as f:
4+
inp = f.read().strip().split("\n")
5+
6+
7+
splitters = set()
8+
for y, line in enumerate(inp):
9+
for x, c in enumerate(line):
10+
if c == "^":
11+
splitters.add(x + y*1j)
12+
elif c == "S":
13+
start = x + y*1j
14+
15+
16+
# Part 1
17+
cur = [start]
18+
beam = set()
19+
splitters_hit = set()
20+
while cur:
21+
p = cur.pop(0)
22+
if p in beam:
23+
continue
24+
beam.add(p)
25+
p += 1j
26+
if p.imag > len(inp):
27+
continue
28+
elif p in splitters:
29+
cur.append(p - 1)
30+
cur.append(p + 1)
31+
splitters_hit.add(p)
32+
else:
33+
cur.append(p)
34+
35+
print(len(splitters_hit))
36+
37+
38+
# Part 2
39+
@cache
40+
def no_timelines(p):
41+
if p.imag > len(inp):
42+
return 1
43+
p += 1j
44+
if p in splitters:
45+
return no_timelines(p + 1) + no_timelines(p - 1)
46+
else:
47+
return no_timelines(p)
48+
49+
50+
print(no_timelines(start))

0 commit comments

Comments
 (0)