diff --git a/2024/day18/solutions.py b/2024/day18/solutions.py new file mode 100644 index 0000000..d1c2c26 --- /dev/null +++ b/2024/day18/solutions.py @@ -0,0 +1,18 @@ +from itertools import count +import networkx as nx + +with open("input") as f: + ns = list(tuple(map(int, l.split(","))) for l in f.read().strip().split("\n")) + + +G = nx.grid_2d_graph(71, 71) + +for i, p in enumerate(ns): + G.remove_node(p) + if i == 1023: + # Part 1 + print(nx.shortest_path_length(G, (0, 0), (70, 70))) + elif not nx.has_path(G, (0, 0), (70, 70)): + # Part 2 + print(p) + break