one big repo for all years

This commit is contained in:
Joshua Seigler 2021-12-02 15:52:52 -05:00
parent 4e1cd98bf1
commit ccc3cdba3a
9 changed files with 0 additions and 0 deletions

1
2020/day01.js Normal file
View file

@ -0,0 +1 @@
let d=document.body.textContent.trim().split('\n').map(a=>parseInt(a)),s=0,f=(a,b,c=2)=>{for(let e,g,h=0;h<d.length;e=d[h++])if(2<c){if(g=f(a+1,b-e,c-1),g)return e*g;}else if(d.includes(b-e))return e*(b-e)};[f(0,2020),f(0,2020,3)]

1
2020/day02.js Normal file
View file

@ -0,0 +1 @@
let d=document.body.textContent.trim().split('\n').map(l=>l.match(/(.+)-(.+) (.): (.+)$/));[d.reduce((s,[_,l,u,n,h])=>{const c=[...h.matchAll(RegExp(n,'g'))].length;return c<=u&&c>=l?s+1:s},0),d.reduce((s,[_,a,b,n,h])=>{return h[a-1]==n^h[b-1]==n?s+1:s},0)];

1
2020/day03.js Normal file
View file

@ -0,0 +1 @@
let d=document.body.textContent.trim().split('\n');let t=(X,Y=1)=>d.filter((l,i)=>(d[i*Y]||'')[i*X%l.length]=='#').length;[t(3),t(1)*t(3)*t(5)*t(7)*t(1,2)];

1
2020/day04.js Normal file
View file

@ -0,0 +1 @@
d=document.body.textContent.replaceAll`cid:`.split`\n\n`;[d.filter(l=>/(:[\s\S]+){7}/m.test(l)).length,d.filter(l=>/((by.:(1...|200[0-2])|iyr:20(1.|20)|eyr:20(2.|30)|hgt:...(n|cm)|hc.:#.{6}|ec.:..[buynlh]|pi.:\d{9})\b[\s\S]*){7}/gm.test(l)).length]

1
2020/day05.js Normal file
View file

@ -0,0 +1 @@
d=document.body.innerText.replaceAll(/[FL]/g,0).replaceAll(/[BR]/g,1).trim().split`\n`.map(c=>parseInt(c,2)).sort((a,b)=>b-a);[d[0],d.find((s,i,S)=>s-S[i+1]==2)-1]

1
2020/day06.js Normal file
View file

@ -0,0 +1 @@
d=(document.body.innerText+`\n`).split`\n\n`,y=g=>[...new Set(g.replace(/\n/g,'').split``)];[d.reduce((a,g)=>a+y(g).length,0),d.reduce((a,g)=>a+y(g).filter(b=>g.split(b).length==g.split`\n`.length+1).length,0)]

1
2020/day07.js Normal file
View file

@ -0,0 +1 @@
G="shiny gold",L=$`body`.innerText.trim().split`\n`.map(a=>/(.+) bags? contain (.*)\./.exec(a)),B=new Map(L.map(([,a,c])=>[a,[...c.matchAll(/(\d+) (.+?) bags?/g)]])),P=new Map,S=a=>(r=P.get(a),new Set(r?r.reduce((a,b)=>[...a,...S(b)],r):[])),E=a=>(B.get(a)||[]).reduce((a,[,b,d])=>a+1*b*E(d),1),B.forEach((a,b)=>a.forEach(([,,a])=>P.set(a,[...(P.get(a)||[]),b]))),[S(G).size,E(G)-1];

1
2020/day08.js Normal file
View file

@ -0,0 +1 @@
L=$`body`.innerText.trim().split`\n`.map(b=>/(.).+ (.+)/.exec(b).slice(1)),X=b=>{for(p=a=0,v=[],O={n:()=>p++,a:b=>{a+=b,p++},j:b=>p+=b};p<b.length;){if(v.includes(p))return[a,0];v.push(p);let[c,d]=b[p];O[c](1*d)}return[a,1]},M=b=>{S=[],b.forEach(([c,d],e)=>{/n|j/.test(c)&&(s=b.slice(),s[e]=["m"<c?"j":"n",d],S.push(s))});for(let c of S)if(result=X(c),result[1])return result},[X(L)[0],M(L)[0]];

1
2020/day15.js Normal file
View file

@ -0,0 +1 @@
I=[9,12,1,4,17,0,18],F=a=>{L=new Map(I.slice(0,-1).map((a,b)=>[a,b]));let b=I[I.length-1];for(let c=I.length;c<a;c++)n=c-1-L.get(b)||0,L.set(b,c-1),b=n;return b},[F(2020),F(3e7)];