-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpart_1.js
33 lines (27 loc) · 1.31 KB
/
part_1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import fs from "node:fs";
import path from "node:path";
import { performance } from "node:perf_hooks";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// ========================= //
// = Copyright (c) NullDev = //
// ========================= //
const INPUT = String(fs.readFileSync(path.join(__dirname, "input.txt"))).trim().split("\n").map(l => l.trim()).filter(e => !!e);
const TMP = [[], []];
INPUT.forEach(line => ( // @ts-ignore
TMP[1 - Number(line.includes(","))].push(line.includes(",") ? line.split(",").map(Number) : [...line.replace("fold along ", "").split("=")])),
);
const pStart = performance.now();
const RES = [
...new Set([
...TMP[0].filter( // @ts-ignore
([x, y]) => (TMP[1][0][0] === "x" && x < TMP[1][0][1]) || (TMP[1][0][0] === "y" && y < TMP[1][0][1]),
).map(x => JSON.stringify(x)),
...TMP[0].filter( // @ts-ignore
([x, y]) => (TMP[1][0][0] === "x" && x > TMP[1][0][1]) || (TMP[1][0][0] === "y" && y > TMP[1][0][1]), // @ts-ignore
).map(([x, y]) => JSON.stringify((TMP[1][0][0] === "y") ? [x, y + 2 * (TMP[1][0][1] - y)] : [x + 2 * (TMP[1][0][1] - x), y])),
]),
].map(x => JSON.parse(x)).length;
const pEnd = performance.now();
console.log("DOT COUNT: " + RES);
console.log(pEnd - pStart);