mirror of
https://github.com/seigler/advent-of-code-browser-console
synced 2025-07-26 00:06: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
day04.js
2
day04.js
|
@ -1 +1 @@
|
|||
let d=document.body.textContent.replaceAll`cid:`.split`\n\n`;[d.filter(l=>/(:[\s\S]+){7}/m.test(l)).length,d.filter(l=>/((by.:(1...|200[0-2])|iyr:20(1.|20)|eyr:20(2.|30)|hgt:...(n|cm)|hc.:#.{6}|ec.:..[buynlh]|pi.:\d{9})\b[\s\S]*){7}/gm.test(l)).length]
|
||||
d=document.body.textContent.replaceAll`cid:`.split`\n\n`;[d.filter(l=>/(:[\s\S]+){7}/m.test(l)).length,d.filter(l=>/((by.:(1...|200[0-2])|iyr:20(1.|20)|eyr:20(2.|30)|hgt:...(n|cm)|hc.:#.{6}|ec.:..[buynlh]|pi.:\d{9})\b[\s\S]*){7}/gm.test(l)).length]
|
3
day05.js
3
day05.js
|
@ -1,2 +1 @@
|
|||
let d=document.body.textContent.replaceAll(/[FL]/g,0).replaceAll(/[BR]/g,1).trim().split`
|
||||
`.map(c=>parseInt(c.slice(0,7),2)*8+parseInt(c.slice(7),2)).sort((a,b)=>b-a);[d[0],d.find((s,i,S)=>s-S[i+1]==2)-1]
|
||||
d=document.body.innerText.replaceAll(/[FL]/g,0).replaceAll(/[BR]/g,1).trim().split`\n`.map(c=>parseInt(c,2)).sort((a,b)=>b-a);[d[0],d.find((s,i,S)=>s-S[i+1]==2)-1]
|
2
day06.js
2
day06.js
|
@ -1 +1 @@
|
|||
let d=(document.body.textContent+`\n`).split`\n\n`,y=g=>[...new Set(g.replace(/\n/g,'').split``)];[d.reduce((a,g)=>a+y(g).length,0),d.reduce((a,g)=>a+y(g).filter(b=>g.split(b).length==g.split`\n`.length+1).length,0)]
|
||||
d=(document.body.innerText+`\n`).split`\n\n`,y=g=>[...new Set(g.replace(/\n/g,'').split``)];[d.reduce((a,g)=>a+y(g).length,0),d.reduce((a,g)=>a+y(g).filter(b=>g.split(b).length==g.split`\n`.length+1).length,0)]
|
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