diff --git a/2021/day03.js b/2021/day03.js index f31ac6e..9f65d7d 100644 --- a/2021/day03.js +++ b/2021/day03.js @@ -1,3 +1,9 @@ I=$('pre').innerText.trim().split`\n`;O=[];I.map(l=>[...l].map((x, i)=>{if(+x)O[i]=(O[i]||0)+1})) -g=t=>parseInt(O.reduce((a,p)=>a+(t^(pO.reduce((a,p,i)=>a+(t^(pa+(p>=I.length/2?1:0),"")] +s=(x,a)=>{n=0;for(p in a){if(x[p]!=+a[p])return n;n++}return n} +Q=parseInt(I.sort((a,b)=>s(a,P)-s(b,P))[0],2); +R=P.map(x=>1-x); +S=parseInt(I.sort((a,b)=>s(a,R)-s(b,R))[0],2); +[Q,S]//day 2, but wrong \ No newline at end of file