diff --git a/day07.js b/day07.js index c844300..ef08c0c 100644 --- a/day07.js +++ b/day07.js @@ -1 +1 @@ -M=new Map,D=$`body`.innerText.trim().split`\n`,D.forEach(d=>{[c,r]=d.split(" bags contain "),b="no other bags."==r?[]:r.split(", ").map(d=>([,q,C]=/(\d+) (.+) bags?\.?/.exec(d),{q:1*q,c:C})),M.set(c,b)}),G="shiny gold",W=new Set,M.forEach((d,a)=>{d.some(d=>d.c===G)&&W.add(a)});for(let d;d!==W.size;)d=W.size,M.forEach((d,a)=>W.has(a)||d.some(d=>W.has(d.c))&&W.add(a));count=d=>0===M.get(d).length?1:M.get(d).reduce((d,a)=>d+a.q*count(a.c),1);[W.size,count(G)-1] \ No newline at end of file +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]; \ No newline at end of file diff --git a/day08.js b/day08.js new file mode 100644 index 0000000..f89a002 --- /dev/null +++ b/day08.js @@ -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{S=[],b.forEach(([c,d],e)=>{/n|j/.test(c)&&(s=b.slice(),s[e]=["m"