Skip to content

Commit d0ad810

Browse files
committed
Add solution to 2024-12-10
1 parent 3a29202 commit d0ad810

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

2024/day10/solutions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import networkx as nx
2+
3+
with open("input") as f:
4+
ls = f.read().strip().split("\n")
5+
6+
board = {i + 1j * j: int(x) for i, l in enumerate(ls) for j, x in enumerate(l)}
7+
8+
G = nx.DiGraph(
9+
(z, z + dz)
10+
for z, h in board.items()
11+
for dz in (1, -1, 1j, -1j)
12+
if board.get(z + dz) == h + 1
13+
)
14+
15+
16+
zeros, nines = [[z for z, x in board.items() if x == v] for v in (0, 9)]
17+
paths = [list(nx.all_simple_paths(G, z1, z2)) for z1 in zeros for z2 in nines]
18+
19+
# Part 1
20+
print(sum(map(any, paths)))
21+
22+
# Part 2
23+
print(sum(map(len, paths)))

0 commit comments

Comments
 (0)