Skip to content

Commit 8333942

Browse files
committed
Add solution to 2024-12-18
1 parent 7ce5770 commit 8333942

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

2024/day18/solutions.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from itertools import count
2+
import networkx as nx
3+
4+
with open("input") as f:
5+
ns = list(tuple(map(int, l.split(","))) for l in f.read().strip().split("\n"))
6+
7+
8+
G = nx.grid_2d_graph(71, 71)
9+
# Part 1
10+
for p in ns[:1024]:
11+
G.remove_node(p)
12+
print(nx.shortest_path_length(G, (0, 0), (70, 70)))
13+
14+
# Part 2
15+
for p in ns[1024:]:
16+
G.remove_node(p)
17+
if not nx.has_path(G, (0, 0), (70, 70)):
18+
print(p)
19+
break

0 commit comments

Comments
 (0)