From 8b5e64e52288bcdd71d2c5e630e99dd0e675089b Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 24 Dec 2020 12:56:31 +0100 Subject: Not so much golfing today --- 2020/24/solve.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 2020/24/solve.js (limited to '2020/24/solve.js') diff --git a/2020/24/solve.js b/2020/24/solve.js new file mode 100644 index 0000000..dca0e75 --- /dev/null +++ b/2020/24/solve.js @@ -0,0 +1,15 @@ +const { _, performance } = require("perf_hooks"); +const fs = require("fs"); +const I = fs.readFileSync("input", "utf8").split("\n"); + +M={e:[0,1,-1],w:[0,-1,1],se:[1,0,-1],nw:[-1,0,1],ne:[-1,1,0],sw:[1,-1,0]}; +N=t=>Object.values(M).map(m=>t.split(",").map(Number).map((c,i)=>c+m[i])).map((n)=>n.join(",")) +B=(t,b)=>N(t).filter(n=>b.has(n)) +W=(t,b)=>N(t).filter(n=>!b.has(n)) +n=b=>{w=new Set([...b].flatMap(t=>W(t, b)));o=new Set();for(t of b){r=B(t,b);if(r.length>0&&r.length<=2)o.add(t)}for(t of w){r=B(t,b);if(r.length==2)o.add(t)}return o} +s=_=>{D=I.map(t=>{D=[];for(i=0;i