blob: 9cdb3ecbcac6a5359c4190eb5f638d83fe699058 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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");
|