mirror of
https://github.com/seigler/advent-of-code-browser-console
synced 2025-07-27 00:26:10 +00:00
one big repo for all years
This commit is contained in:
parent
4e1cd98bf1
commit
ccc3cdba3a
9 changed files with 0 additions and 0 deletions
1
2020/day07.js
Normal file
1
2020/day07.js
Normal 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];
|
Loading…
Add table
Add a link
Reference in a new issue