-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpart_2.js
27 lines (21 loc) · 1.03 KB
/
part_2.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
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\n");
const pStart = performance.now();
const res = INPUT.map(x => x.split("\n").map(y => y.split("").map(z => z === "#" ? 1 : 0)))
.map(g => [
g.map(x => parseInt(x.join(""), 2)),
g[0].map((_, i) => parseInt(g.map(x => x[i]).join(""), 2)),
].map(x => x.findIndex((_, i) => i !== 0 && x.slice(0, i).reverse().map((y, j) => !x[i + j]
? 0
: (y ^ x[i + j]).toString(2).split("").filter(z => z === "1").length).reduce((a, b) => a + b) === 1)),
).map(([x, y]) => x === -1 ? y : x * 100).reduce((a, b) => a + b);
const pEnd = performance.now();
console.log("SUM OF NEW REFLECTIONS: " + res);
console.log(pEnd - pStart);