mirror of
https://github.com/seigler/advent-of-code-browser-console
synced 2025-07-27 00:26:10 +00:00
Improving some previous days
This commit is contained in:
parent
048bb56462
commit
ba2a91c553
4 changed files with 4 additions and 5 deletions
2
day07.js
2
day07.js
|
@ -1 +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];
|
||||
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]
|
Loading…
Add table
Add a link
Reference in a new issue