-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpart_1.js
22 lines (16 loc) · 855 Bytes
/
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
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");
const pStart = performance.now();
const res = [...INPUT[0]].map((_, idx) => INPUT.map(row => row[idx]).reverse().join("")) // @ts-ignore
.map(row => row.replaceAll(/[\.O]+/g, r => r.replaceAll(".", "").padStart(r.length, ".")))
.reduce((sum, row) => sum + [...row].reduce((rSum, isRock, idx) => rSum + (isRock === "O" ? idx + 1 : 0), 0), 0);
const pEnd = performance.now();
console.log("LOAD ON SUPPORT BEAMS: " + res);
console.log(pEnd - pStart);