Skip to content

Commit 990f954

Browse files
committed
js day 8 oneliner
1 parent 6505429 commit 990f954

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

js/day08.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
console.log(
2+
require("fs")
3+
.readFileSync("data/day8.txt", "utf-8")
4+
.trim().split("\n")
5+
.map(x=>x.trim().split(" "))
6+
.map(([o,v],i)=>[o=='acc'?0:o=='jmp'?1:2,+v])
7+
.reduce((a,b,c,d)=>[
8+
c=>c.map(([o,a],i)=>
9+
`case ${i}:${o==0?`a+=${a}`:o==1?`i+=${a-1}`:""};break;`)
10+
.reduce(([a,b],c)=>[a+c,b+1],["",0])
11+
.reduce((s,c)=>eval(`x=Array(${c}).fill(0);a=0;i=0;for(;;){if(i>${c-1}
12+
||x[i])break;x[i]++;switch(i++){${s}}}[a,x[i]]`)),
13+
d,d]).map((x,i,[f])=>i==0?0:i==1?f(x)[0]:x.map((_,i,a,j=JSON)=>
14+
f(x=j.parse(j.stringify(a)),y=x[i][0],x[i][0]=y==0?y:y==1?2:1))
15+
.filter(([_,b])=>!b)[0][0]).slice(1));
16+

0 commit comments

Comments
 (0)