diff --git a/Day6/Part2.js b/Day6/Part2.js index 3ae0918..0060d1b 100644 --- a/Day6/Part2.js +++ b/Day6/Part2.js @@ -2,23 +2,23 @@ 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 time = parseInt( + input[0] + .split(/\s{1,}/) + .slice(1) + .reduce((a, i) => a + i) +); +const distance = parseInt( + input[1] + .split(/\s{1,}/) + .slice(1) + .reduce((a, i) => a + i) +); +console.log( + [...Array(time - 1).keys()] + .map((b) => (time - (b + 1)) * (b + 1)) + .filter((b) => b > distance).length +); const t1 = performance.now(); console.log(`Runtime: ${t1 - t0}ms`);