Skip to content

Commit 20f0ae6

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

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

2024/day18/solutions.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
10+
for i, p in enumerate(ns):
11+
G.remove_node(p)
12+
if i == 1023:
13+
# Part 1
14+
print(nx.shortest_path_length(G, (0, 0), (70, 70)))
15+
elif not nx.has_path(G, (0, 0), (70, 70)):
16+
# Part 2
17+
print(p)
18+
break

0 commit comments

Comments
 (0)