From ed341f7f190cec49d0c3d6353f63234ce5b58bef Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 13 Dec 2021 16:07:52 +0100 Subject: ez --- 2021/12/solve.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 2021/12/solve.js (limited to '2021/12/solve.js') diff --git a/2021/12/solve.js b/2021/12/solve.js new file mode 100644 index 0000000..1a2819f --- /dev/null +++ b/2021/12/solve.js @@ -0,0 +1,24 @@ +const { _, performance } = require("perf_hooks"); +const fs = require("fs"); +const f = fs.readFileSync("input", "utf8").split("\n"); + +function solve() { + const t = {}; + f.forEach((l) => { + let [s, d] = l.split("-"); + if (!s || !d) return; + t[s] = (t[s] || []).concat([d]); + t[d] = (t[d] || []).concat([s]); + }); + + // Lol + one=(n="start",f=new Set())=>n[2]=='d'||t[n].reduce((p,c)=>p+(f.has(c)?0:one(c,n==n.toLowerCase()?new Set([...f,n]):f)),0); + two=(n="start",f=new Set(),u=false)=>n[2]=='d'||t[n].reduce((p,c)=>p+((c[2]=='a'||(f.has(c)&&u))?0:two(c,n==n.toLowerCase()?new Set([...f,n]):f,f.has(c)||u)),0); + + console.log(one(), two()); +} + +const tic = performance.now(); +solve(); +const toc = performance.now(); +console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds"); -- cgit v1.2.3