From 5986c9bd69524e70962be8c1a67eeb19e6767255 Mon Sep 17 00:00:00 2001 From: Joshua Seigler Date: Thu, 2 Dec 2021 15:53:04 -0500 Subject: [PATCH] 2021 solutions so far --- 2021/day01.js | 1 + 2021/day02.js | 1 + 2 files changed, 2 insertions(+) create mode 100644 2021/day01.js create mode 100644 2021/day02.js diff --git a/2021/day01.js b/2021/day01.js new file mode 100644 index 0000000..ddb16ae --- /dev/null +++ b/2021/day01.js @@ -0,0 +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 diff --git a/2021/day02.js b/2021/day02.js new file mode 100644 index 0000000..3322802 --- /dev/null +++ b/2021/day02.js @@ -0,0 +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