mirror of
https://github.com/Baipyrus/AoC-23.git
synced 2024-09-11 08:19:44 +00:00
init d6p2
This commit is contained in:
parent
49bc03e1ef
commit
45667e1d4e
24
Day6/Part2.js
Normal file
24
Day6/Part2.js
Normal file
|
@ -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`);
|
Loading…
Reference in New Issue
Block a user