diff options
author | Marvin Borner | 2022-12-05 09:04:45 +0100 |
---|---|---|
committer | Marvin Borner | 2022-12-05 09:04:45 +0100 |
commit | a36c6fe4b3fe93c936d40dcca41f5e8cbf4987d7 (patch) | |
tree | 915d2a1ec31b9ff01f61879bf93037ff3642a590 /2022/05/solve.js | |
parent | d5f822bcad063435ac1a48f0a0dae41a9b155d73 (diff) |
golf? a bit
Diffstat (limited to '2022/05/solve.js')
-rw-r--r-- | 2022/05/solve.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/2022/05/solve.js b/2022/05/solve.js new file mode 100644 index 0000000..9cdb3ec --- /dev/null +++ b/2022/05/solve.js @@ -0,0 +1,15 @@ +function run(v) +{ + [s,p]=require("fs").readFileSync("input", "utf8").split("\n\n"); + l=s.split("\n").slice(0,-1).map(a=>a.match(/.{1,4}/g)) + s=l[0].map((c,i)=>l.map(r=>r[i])).map(a=>a.filter(b=>b[0]=='[')) + p.split("\n").slice(0,-1).forEach(a=>{b=a.split(" ");w=+b[1];r=+b[3]-1;t=+b[5]-1;p=s[r].slice(0,w);if(!(v%2))p.reverse();s[t]=[...p,...s[t]];s[r].splice(0,w);}); + return s.map(a=>a[0]).join(""); +} + +const tic = performance.now(); +console.log(run(9000)); +console.log(run(9001)); +const toc = performance.now(); +console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds"); + |