AoC-23/Day6/Part1.js

25 lines
539 B
JavaScript
Raw Normal View History

2023-12-08 08:37:26 +00:00
import { readFileSync } from "fs";
const t0 = performance.now();
2023-12-08 08:55:52 +00:00
const input = readFileSync("input.txt").toString().split("\n");
const time = input[0]
.split(/\s{1,}/)
.slice(1)
.map(Number);
const distance = input[1]
.split(/\s{1,}/)
.slice(1)
.map(Number);
2023-12-08 10:35:23 +00:00
const records = time
.map(
(a, i) =>
[...Array(a - 1).keys()]
.map((b) => (a - (b + 1)) * (b + 1))
.filter((b) => b > distance[i]).length
)
.reduce((a, i) => a * i);
console.log(records);
2023-12-08 08:37:26 +00:00
const t1 = performance.now();
console.log(`Runtime: ${t1 - t0}ms`);