From db2b9215aad6679077225d7efbe21fa17303b152 Mon Sep 17 00:00:00 2001 From: Joshua Seigler Date: Mon, 7 Dec 2020 22:09:45 -0500 Subject: [PATCH 1/2] Day 7 full recursion. Still too big --- day07.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 23db4666a9061c87db7fb13f56b1294d174a2e8d Mon Sep 17 00:00:00 2001 From: Joshua Seigler Date: Tue, 8 Dec 2020 02:08:14 -0500 Subject: [PATCH 2/2] Day 8 --- day08.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 day08.js 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"