-
Notifications
You must be signed in to change notification settings - Fork 5
/
part_2.js
23 lines (17 loc) · 885 Bytes
/
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
"use strict";
const fs = require("node:fs");
const path = require("node:path");
const { performance } = require("node:perf_hooks");
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);