From b15131bf1efa75289bdcc3fe18429b67eab96b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sat, 14 Dec 2024 22:34:22 +0100 Subject: [PATCH] Add dot file to 2021 day 12. --- src/holt59/aoc/2021/day12.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/holt59/aoc/2021/day12.py b/src/holt59/aoc/2021/day12.py index 2bdf8ba..d10a7cd 100644 --- a/src/holt59/aoc/2021/day12.py +++ b/src/holt59/aoc/2021/day12.py @@ -46,5 +46,19 @@ class Solver(BaseSolver): if b != "end" and a != "start": neighbors[b].append(a) + if self.files: + graph = "graph {\n" + for node, neighbors_of in neighbors.items(): + graph += ( + " ".join( + f"{node} -- {neighbor};" + for neighbor in neighbors_of + if node <= neighbor or node == "start" or neighbor == "end" + ) + + "\n" + ) + graph += "}\n" + self.files.create("graph.dot", graph.encode(), False) + yield len(list(enumerate_paths(neighbors))) yield len(list(enumerate_paths(neighbors, 1)))