aboutsummaryrefslogtreecommitdiff
path: root/2021/12
diff options
context:
space:
mode:
authorMarvin Borner2021-12-13 16:07:52 +0100
committerMarvin Borner2021-12-13 19:21:41 +0100
commited341f7f190cec49d0c3d6353f63234ce5b58bef (patch)
tree33b15183e0e76ff99a679d3ff4a68486f2f5128a /2021/12
parenta46a5cf547127ade88ce9ced2cc459086f770d07 (diff)
ez
Diffstat (limited to '2021/12')
-rw-r--r--2021/12/Makefile4
-rw-r--r--2021/12/input24
-rw-r--r--2021/12/solve.js24
3 files changed, 52 insertions, 0 deletions
diff --git a/2021/12/Makefile b/2021/12/Makefile
new file mode 100644
index 0000000..9295d89
--- /dev/null
+++ b/2021/12/Makefile
@@ -0,0 +1,4 @@
+run:
+ @node solve.js
+
+time: run
diff --git a/2021/12/input b/2021/12/input
new file mode 100644
index 0000000..1d5c9fe
--- /dev/null
+++ b/2021/12/input
@@ -0,0 +1,24 @@
+re-js
+qx-CG
+start-js
+start-bj
+qx-ak
+js-bj
+ak-re
+CG-ak
+js-CG
+bj-re
+ak-lg
+lg-CG
+qx-re
+WP-ak
+WP-end
+re-lg
+end-ak
+WP-re
+bj-CG
+qx-start
+bj-WP
+JG-lg
+end-lg
+lg-iw
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");