-
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) · 696 Bytes
/
part_2.js
File metadata and controls
21 lines (15 loc) · 696 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")))
.split("\n\n").map(e => e.split("\n").map(Number));
const pStart = performance.now();
const result = INPUT.map(e => e.reduce((a, b) => a + b)).sort((a, b) => b - a).slice(0, 3).reduce((a, b) => a + b);
const pEnd = performance.now();
console.log("CALORIES OF TOP 3 ELVES: " + result);
console.log(pEnd - pStart);