-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpart_2.js
27 lines (21 loc) · 826 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
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 CONTENT_READ = String(fs.readFileSync(path.join(__dirname, "input.txt")));
const pStart = performance.now();
const UNIQUE = CONTENT_READ.replace(/\n\r/g, "\n")
.replace(/\r/g, "\n")
.split(/\n{2,}/g)
.map(l => l.trim())
.reduce((count, group) => {
const p = group.split(/\s+/).map((x) => [...x]);
return count + p[0].filter((a) => p.every((as) => as.includes(a))).length;
}, 0);
const pEnd = performance.now();
console.log("TOTAL COUNT: " + UNIQUE);
console.log(pEnd - pStart);