-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpart_2.js
More file actions
21 lines (15 loc) · 755 Bytes
/
part_2.js
File metadata and controls
21 lines (15 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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").map(l => l.split(","));
const pStart = performance.now();
const result = INPUT.map(([r1, r2]) => [r1.split("-").map(Number), r2.split("-").map(Number)])
.filter(([r1, r2]) => (r1[0] <= r2[1] && r1[1] >= r2[0]) || (r2[0] <= r1[1] && r2[1] >= r1[0])).length;
const pEnd = performance.now();
console.log("OVERLAPS: " + result);
console.log(pEnd - pStart);