-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpart_1.js
27 lines (21 loc) · 972 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
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");
const pStart = performance.now();
const res = INPUT.reduce((
acc, e, _, __,
k = new RegExp("^\\.*#{" + e.split(" ")[1].split(",").join("}\\.+#{") + "}\\.*$", ""),
solve = (s, idx = s.indexOf("?")) => (!s.includes("?"))
? [s]
: solve(s.substring(0, idx) + "." + s.substring(idx + 1))
.concat(solve(s.substring(0, idx) + "#" + s.substring(idx + 1))),
) => solve(e.split(" ")[0]).reduce((iAcc, j) => iAcc + (k.test(j) ? 1 : 0), acc), 0);
const pEnd = performance.now();
console.log("SUM OF COUNTS: " + res);
console.log(pEnd - pStart);