diff --git a/day04.js b/day04.js index e912c02..2b9c1f0 100644 --- a/day04.js +++ b/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] \ No newline at end of file +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] \ No newline at end of file diff --git a/day05.js b/day05.js index bb6c85f..e3a8350 100644 --- a/day05.js +++ b/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] \ No newline at end of file +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] \ No newline at end of file diff --git a/day06.js b/day06.js index 498b3c8..0294999 100644 --- a/day06.js +++ b/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)] \ No newline at end of file +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)] \ No newline at end of file diff --git a/day07.js b/day07.js index 85f4a38..c844300 100644 --- a/day07.js +++ b/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]; \ No newline at end of file +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] \ No newline at end of file