summaryrefslogtreecommitdiff
path: root/day-8/script.ts
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-12-09 02:25:17 +0300
committereug-vs <eugene@eug-vs.xyz>2023-12-09 02:25:17 +0300
commita65bf01f5a8aaed52f38bb27e7c99b88e8b9b0f6 (patch)
treebda4d31326ade6378d74df34edd0637cc5be3a46 /day-8/script.ts
parente57d0b97c8cb365d7d0a3ee7a0fc9294d2c8dcee (diff)
downloadaoc-2023-a65bf01f5a8aaed52f38bb27e7c99b88e8b9b0f6.tar.gz
feat(day-8): add cool visualization
Diffstat (limited to 'day-8/script.ts')
-rw-r--r--day-8/script.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/day-8/script.ts b/day-8/script.ts
index 87e33cd..a9870c1 100644
--- a/day-8/script.ts
+++ b/day-8/script.ts
@@ -55,3 +55,13 @@ const result = startingNodes
.reduce((acc, x) => lcm(acc, x), 1);
console.log({ result });
+
+// Visualization into graphviz file
+// $ neato graph.dot -Tpng -o out.png
+const dotFile = "graph.dot";
+fs.writeFileSync(dotFile, "digraph aoc {\n");
+nodes.forEach((node) => {
+ fs.appendFileSync(dotFile, ` ${node.name} -> ${nodes[node.left].name};\n`);
+ fs.appendFileSync(dotFile, ` ${node.name} -> ${nodes[node.right].name};\n`);
+});
+fs.appendFileSync(dotFile, "}\n");