Day 7, too big

This commit is contained in:
Joshua Seigler 2020-12-07 20:03:55 +00:00
parent e8320a1240
commit 048bb56462

1
day07.js Normal file
View file

@ -0,0 +1 @@
m=new Map,d=$`body`.innerText.trim().split`\n`,d.forEach(a=>{[c,r]=a.split(" bags contain "),b="no other bags."==r?[]:r.split(", ").map(a=>([,q,C]=/(\d+) (.+) bags?\.?/.exec(a),{q:1*q,c:C})),m.set(c,b)}),sg="shiny gold",W=new Set,m.forEach((a,e)=>{a.some(a=>a.c===sg)&&W.add(e)});for(let a;a!==W.size;)a=W.size,m.forEach((a,e)=>{!W.has(e)&&a.some(a=>W.has(a.c))&&W.add(e)});count=a=>0===m.get(a).length?1:m.get(a).reduce((a,e)=>a+e.q*count(e.c),1);[W.size,count(sg)-1];