mirror of
https://github.com/seigler/advent-of-code-browser-console
synced 2025-07-26 00:06:10 +00:00
Day 7, too big
This commit is contained in:
parent
e8320a1240
commit
048bb56462
1 changed files with 1 additions and 0 deletions
1
day07.js
Normal file
1
day07.js
Normal 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];
|
Loading…
Add table
Add a link
Reference in a new issue