mirror of
https://github.com/Baipyrus/AoC-23.git
synced 2024-12-27 04:21:45 +00:00
solve d6p2
This commit is contained in:
parent
45667e1d4e
commit
596693be4a
@ -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(
|
||||||
.split(/\s{1,}/)
|
input[0]
|
||||||
.slice(1)
|
.split(/\s{1,}/)
|
||||||
.map(Number);
|
.slice(1)
|
||||||
const distance = input[1]
|
.reduce((a, i) => a + i)
|
||||||
.split(/\s{1,}/)
|
);
|
||||||
.slice(1)
|
const distance = parseInt(
|
||||||
.map(Number);
|
input[1]
|
||||||
const records = time
|
.split(/\s{1,}/)
|
||||||
.map(
|
.slice(1)
|
||||||
(a, i) =>
|
.reduce((a, i) => a + i)
|
||||||
[...Array(a - 1).keys()]
|
);
|
||||||
.map((b) => (a - (b + 1)) * (b + 1))
|
console.log(
|
||||||
.filter((b) => b > distance[i]).length
|
[...Array(time - 1).keys()]
|
||||||
)
|
.map((b) => (time - (b + 1)) * (b + 1))
|
||||||
.reduce((a, i) => a * i);
|
.filter((b) => b > distance).length
|
||||||
console.log(records);
|
);
|
||||||
|
|
||||||
const t1 = performance.now();
|
const t1 = performance.now();
|
||||||
console.log(`Runtime: ${t1 - t0}ms`);
|
console.log(`Runtime: ${t1 - t0}ms`);
|
||||||
|
Loading…
Reference in New Issue
Block a user