diff options
author | Marvin Borner | 2020-12-23 13:31:38 +0100 |
---|---|---|
committer | Marvin Borner | 2020-12-23 13:31:38 +0100 |
commit | 4d171a490d1865d9a535bb5d9a1ac12cb4f02211 (patch) | |
tree | 061854455b6beb3b2209d9069510843404a915ba | |
parent | 8ee4d039237f50d818b487a65c08c1ef3905f909 (diff) |
I'm confused
-rw-r--r-- | 2020/23/Makefile | 2 | ||||
-rw-r--r-- | 2020/23/input | 1 | ||||
-rw-r--r-- | 2020/23/solve.js | 48 |
3 files changed, 51 insertions, 0 deletions
diff --git a/2020/23/Makefile b/2020/23/Makefile new file mode 100644 index 0000000..dad052e --- /dev/null +++ b/2020/23/Makefile @@ -0,0 +1,2 @@ +run: + @node solve.js diff --git a/2020/23/input b/2020/23/input new file mode 100644 index 0000000..ab40847 --- /dev/null +++ b/2020/23/input @@ -0,0 +1 @@ +389125467 diff --git a/2020/23/solve.js b/2020/23/solve.js new file mode 100644 index 0000000..f16443b --- /dev/null +++ b/2020/23/solve.js @@ -0,0 +1,48 @@ +const { _, performance } = require("perf_hooks"); +const fs = require("fs"); +const data = fs + .readFileSync("input", "utf8") + .split("\n")[0] + .split("") + .map((x) => parseInt(x)); + +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; +} + +const tic = performance.now(); +console.log(partOne()); +console.log(partTwo()); +const toc = performance.now(); +console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds"); |