From 833394251f880db0d86660e0f9a22fc2bfa67c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Fuglede=20J=C3=B8rgensen?= Date: Wed, 18 Dec 2024 06:15:10 +0100 Subject: [PATCH] Add solution to 2024-12-18 --- 2024/day18/solutions.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 2024/day18/solutions.py diff --git a/2024/day18/solutions.py b/2024/day18/solutions.py new file mode 100644 index 0000000..5a39c45 --- /dev/null +++ b/2024/day18/solutions.py @@ -0,0 +1,19 @@ +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) +# Part 1 +for p in ns[:1024]: + G.remove_node(p) +print(nx.shortest_path_length(G, (0, 0), (70, 70))) + +# Part 2 +for p in ns[1024:]: + G.remove_node(p) + if not nx.has_path(G, (0, 0), (70, 70)): + print(p) + break