-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpart_1.js
27 lines (21 loc) · 908 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").filter(Boolean);
const pStart = performance.now();
const res = INPUT.filter(
(line, _, __, levels = line.split(" ").map(Number),
) => levels.every(
(level, i, arr, dir = levels[1] - levels[0]) => i === 0 ||
(Math.abs(level - arr[i - 1]) >= 1 &&
Math.abs(level - arr[i - 1]) <= 3 &&
(dir < 0 ? level <= arr[i - 1] : level >= arr[i - 1])),
)).length;
const pEnd = performance.now();
console.log("SAFE REPORTS: " + res);
console.log(pEnd - pStart);