aboutsummaryrefslogtreecommitdiff
path: root/2020/23
diff options
context:
space:
mode:
authorMarvin Borner2020-12-23 16:24:32 +0100
committerMarvin Borner2020-12-23 16:26:22 +0100
commitec00b6eb28c484ea07212fc7582176a5b2e187e1 (patch)
tree7f67f58bd2954758f9521141eb3b64f9cdbb4544 /2020/23
parent4d171a490d1865d9a535bb5d9a1ac12cb4f02211 (diff)
Golfygolfgolf
Diffstat (limited to '2020/23')
-rw-r--r--2020/23/input2
-rw-r--r--2020/23/solve.js46
2 files changed, 6 insertions, 42 deletions
diff --git a/2020/23/input b/2020/23/input
index ab40847..2a495d1 100644
--- a/2020/23/input
+++ b/2020/23/input
@@ -1 +1 @@
-389125467
+463528179
diff --git a/2020/23/solve.js b/2020/23/solve.js
index f16443b..7cd6e9d 100644
--- a/2020/23/solve.js
+++ b/2020/23/solve.js
@@ -1,48 +1,12 @@
const { _, performance } = require("perf_hooks");
const fs = require("fs");
-const data = fs
- .readFileSync("input", "utf8")
- .split("\n")[0]
- .split("")
- .map((x) => parseInt(x));
+const D = fs.readFileSync("input", "utf8").split("\n")[0].split("").map(Number);
-function partOne() {
- let moves = 11;
-
- let cur = 0;
- const cups = data;
- while (--moves) {
- // Pick up
- const picks = [];
- for (let i = 0; i < 3; i++) picks[i] = cups.splice(cur + 1, 1);
-
- // Find destination
- let dest = 0;
- let decr = 1;
- while (!dest) {
- dest = cups.filter((x) => x == cups[cur] - decr)[0];
- if (!dest) decr++;
-
- if (decr > cups.length) {
- dest = Math.max.apply(Math, cups);
- break;
- }
- }
-
- cups.splice.apply(cups, [cups.indexOf(dest) + 1, 0].concat(picks));
- console.log("Cups: " + cups, "Picks: " + picks, "Dest: " + dest);
-
- cur++;
- }
- return 0;
-}
-
-function partTwo() {
- return 0;
-}
+// Yeeehaw
+P=(I,C,M)=>{c=new Uint32Array(C+1).map((_,i)=>i+1);for(i=0;i<c.length;i++)c[I[i]]=I[(i+1)%I.length];c[0]=I[0];if(C>I.length){c[I[I.length-1]]=I.length+1;c[c.length-1]=I[0]}for(m=1;m<=M;m++){p=[c[c[0]],c[c[c[0]]],c[c[c[c[0]]]]];d=c[0]-1||C;while(p.includes(d))d=d-1||C;c[c[0]]=c[p[2]];c[p[2]]=c[d];c[d]=p[0];c[0]=c[c[0]]}return c};O=()=>{C=P(D,9,100);r=[];c=C[1];while(c!=1){r.push(c);c=C[c]}return +r.join("")};T=()=>{C=P(D,1e6,1e7);return C[1]*C[C[1]]}
const tic = performance.now();
-console.log(partOne());
-console.log(partTwo());
+console.log(O());
+console.log(T());
const toc = performance.now();
console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds");