From 53f2b9aec4ce2f3a03cf8e59bd83de46777ddc56 Mon Sep 17 00:00:00 2001 From: Joshua Seigler Date: Mon, 6 Dec 2021 11:40:44 -0500 Subject: [PATCH] multiple improvements, day 5 progress --- 2021/day01.js | 2 +- 2021/day02.js | 2 +- 2021/day03.js | 3 +++ 2021/day05.js | 2 +- 2021/day06.js | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 2021/day03.js diff --git a/2021/day01.js b/2021/day01.js index ddb16ae..e3cd570 100644 --- a/2021/day01.js +++ b/2021/day01.js @@ -1 +1 @@ -d=$('body').innerText.trim().split`\n`;t=(d,n)=>d.reduce((a,x,i)=>a+(+x>d[i-n]),0);[t(d,1),t(d,3)] \ No newline at end of file +d=$('pre').innerText.trim().split`\n`;t=(d,n)=>d.reduce((a,x,i)=>a+(+x>d[i-n]),0);[t(d,1),t(d,3)] \ No newline at end of file diff --git a/2021/day02.js b/2021/day02.js index 3322802..c8be2dd 100644 --- a/2021/day02.js +++ b/2021/day02.js @@ -1 +1 @@ -d=$('body').innerText.trim().split`\n`.map(l=>l.split` `);[(j=d.reduce((a,[c,v])=>({f:a=>v=>(a.h+=v,a),d:a=>v=>(a.d+=v,a),u:a=>v=>(a.d-=v,a)}[c[0]](a)(+v)),{h:0,d:0}),j.h*j.d),(k=d.reduce((a,[c,v])=>({f:a=>v=>(a.h+=v,a.d+=a.a*v,a),d:a=>v=>(a.a+=v,a),u:a=>v=>(a.a-=v,a)}[c[0]](a)(+v)),{h:0,d:0,a:0}),k.h*k.d)] \ No newline at end of file +d=$('pre').innerText.trim().split`\n`.map(l=>l.split` `);[(j=d.reduce((a,[c,v])=>({f:a=>v=>(a.h+=v,a),d:a=>v=>(a.d+=v,a),u:a=>v=>(a.d-=v,a)}[c[0]](a)(+v)),{h:0,d:0}),j.h*j.d),(k=d.reduce((a,[c,v])=>({f:a=>v=>(a.h+=v,a.d+=a.a*v,a),d:a=>v=>(a.a+=v,a),u:a=>v=>(a.a-=v,a)}[c[0]](a)(+v)),{h:0,d:0,a:0}),k.h*k.d)] \ No newline at end of file diff --git a/2021/day03.js b/2021/day03.js new file mode 100644 index 0000000..f31ac6e --- /dev/null +++ b/2021/day03.js @@ -0,0 +1,3 @@ +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^(p(V=new Map(),$`pre`.innerText.trim().split`\n`.map(l=>l.split(/ -> |,/).map(x=>+x)).map(([a,b,c,d])=>{for(X=s(c-a),Y=s(d-b),x=a,y=b;!(D*X*Y)&(x!=c+X|y!=d+Y);x+=X,y+=Y){k=`${x},${y}`;V.set(k,(V.get(k)||0)+1)}}),[...V.values()].filter(x=>x>1).length);[S(1),S()] \ No newline at end of file +s=Math.sign,S=D=>(V=new Map(),$('pre').innerText.trim().split`\n`.map(l=>l.split(/ -> |,/).map(x=>+x)).map(([a,b,c,d])=>{for(X=s(c-a),Y=s(d-b),x=a,y=b;!(D*X*Y)&(x!=c+X|y!=d+Y);x+=X,y+=Y){k=`${x},${y}`;V.set(k,(V.get(k)||0)+1)}}),[...V.values()].filter(x=>x>1).length);[S(1),S()] \ No newline at end of file diff --git a/2021/day06.js b/2021/day06.js index 0573019..873b24a 100644 --- a/2021/day06.js +++ b/2021/day06.js @@ -1 +1 @@ -[80,256].map(d=>{B=Array(9).fill(0);$`pre`.innerText.trim().split`,`.map(f=>B[+f]++);for(i=0;ia+x,0)}) \ No newline at end of file +[80,256].map(d=>{B=Array(9).fill(0);$('pre').innerText.trim().split`,`.map(f=>B[+f]++);for(i=0;++ia+x,0)}) \ No newline at end of file