diff options
author | Marvin Borner | 2020-12-21 16:42:59 +0100 |
---|---|---|
committer | Marvin Borner | 2020-12-21 16:42:59 +0100 |
commit | f4adb9df46a64f274afd9decec465e2d89a5e516 (patch) | |
tree | 5e51b1d0a63f9d3ce5103cbc8902c79778f2ec9a | |
parent | 0c4564b03d362167d9f867f1154235fb4a9fab17 (diff) |
Added part 2 (golfed it a bit)
-rw-r--r-- | 2020/21/solve.js | 10 | ||||
-rw-r--r-- | 2020/README | 40 |
2 files changed, 25 insertions, 25 deletions
diff --git a/2020/21/solve.js b/2020/21/solve.js index 8202603..e39e76f 100644 --- a/2020/21/solve.js +++ b/2020/21/solve.js @@ -2,12 +2,10 @@ const { _, performance } = require("perf_hooks"); const fs = require("fs"); const d = fs.readFileSync("input", "utf8").split("\n"); -function partOne() { -c=" (contains ";f=d.map(x=>({i:x.split(c)[0].split(" "),a:x.split(c)[1].split(")")[0].split(", ")}));a=new Map();for(g of f)for(b of g.a)a.set(b,new Set(a.get(b)?[...g.i].filter(x=>a.get(b).has(x)):g.i));return f.map(x=>x.i).flat().filter(x=>!new Set([...a.values()].reduce((a,b)=>[...a,...b],[])).has(x)).length; -} - const tic = performance.now(); -console.log(partOne()); -//console.log(partTwo()); + +// YAYY +(()=>{c=" (contains ";f=d.map(x=>({i:x.split(c)[0].split(" "),a:x.split(c)[1].split(")")[0].split(", ")}));a=new Map();for(g of f)for(b of g.a)a.set(b,new Set(a.get(b)?[...g.i].filter(x=>a.get(b).has(x)):g.i));console.log(f.map(x=>x.i).flat().filter(x=>!new Set([...a.values()].reduce((a,b)=>[...a,...b],[])).has(x)).length);o=Array.from(a,([b,i])=>({b,i}));let n;do{n=!1;for(b of o)if(b.i.size>1){b.i=new Set([...b.i].filter(x=>!o.filter(x=>x.i.size==1).map(x=>[...x.i][0]).includes(x)));n=!0}}while(n)console.log(o.sort((a,b)=>a.b.localeCompare(b.b)).map(x=>[...x.i][0]).join(','))})() + const toc = performance.now(); console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds"); diff --git a/2020/README b/2020/README index d0aaae9..68de215 100644 --- a/2020/README +++ b/2020/README @@ -1,19 +1,21 @@ -Day 01: TIME: 0.006000 seconds -Day 02: TIME: 0.000710 seconds -Day 03: TIME: 0.000174 seconds -Day 04: TIME: 0.001569 seconds -Day 05: TIME: 0.000492 seconds -Day 06: TIME: 0.021799 seconds -Day 07: TIME: 0.056844 seconds -Day 08: TIME: 0.021424 seconds -Day 09: TIME: 0.012570 seconds -Day 10: TIME: 0.000013 seconds -Day 11: TIME: 0.036652 seconds -Day 12: TIME: 0.000616 seconds -Day 13: TIME: 0.000052 seconds -Day 14: TIME: 0.023437 seconds -Day 15: TIME: 4.195079 seconds -Day 16: TIME: 0.000809 seconds -Day 17: TIME: 0.196286 seconds -Day 18: TIME: 0.000249 seconds -Day 19: TIME: 0.924737 seconds +Day 01: TIME: 0.008000 seconds +Day 02: TIME: 0.003061 seconds +Day 03: TIME: 0.000392 seconds +Day 04: TIME: 0.006114 seconds +Day 05: TIME: 0.001041 seconds +Day 06: TIME: 0.024731 seconds +Day 07: TIME: 0.055883 seconds +Day 08: TIME: 0.021691 seconds +Day 09: TIME: 0.013926 seconds +Day 10: TIME: 0.000039 seconds +Day 11: TIME: 0.096766 seconds +Day 12: TIME: 0.000917 seconds +Day 13: TIME: 0.000115 seconds +Day 14: TIME: 0.059947 seconds +Day 15: TIME: 5.490485 seconds +Day 16: TIME: 0.003559 seconds +Day 17: TIME: 0.276986 seconds +Day 18: TIME: 0.001221 seconds +Day 19: TIME: 1.353835 seconds +Day 20: TIME: 0.000376 seconds +Day 21: TIME: 0.032914 seconds |