Skip to content

Commit a37da74

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

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

2024/day18/solutions.py

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

0 commit comments

Comments
 (0)