From 45667e1d4e68b4e8063aa224fce14962fb5add5d Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Fri, 8 Dec 2023 11:35:48 +0100 Subject: [PATCH] init d6p2 --- Day6/Part2.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Day6/Part2.js diff --git a/Day6/Part2.js b/Day6/Part2.js new file mode 100644 index 0000000..3ae0918 --- /dev/null +++ b/Day6/Part2.js @@ -0,0 +1,24 @@ +import { readFileSync } from "fs"; +const t0 = performance.now(); + +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); +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); + +const t1 = performance.now(); +console.log(`Runtime: ${t1 - t0}ms`);