solve d6p2

This commit is contained in:
Baipyrus 2023-12-08 11:42:38 +01:00
parent 45667e1d4e
commit 596693be4a

View File

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