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)))