summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-12-06 13:29:08 +0300
committereug-vs <eugene@eug-vs.xyz>2023-12-06 13:29:08 +0300
commit31e9940088d57fc95001dd9ab629ca4fa2a1278b (patch)
treeadebd846bf02e05e6f983e2c981c6e782eef0a9c
parentc49ccc971c3a7b05dc08386833bfa4935456ff15 (diff)
downloadaoc-2023-31e9940088d57fc95001dd9ab629ca4fa2a1278b.tar.gz
feat(day-6): add part 2 solution
-rw-r--r--day-6/script.ts12
1 files changed, 4 insertions, 8 deletions
diff --git a/day-6/script.ts b/day-6/script.ts
index 951e056..7cd15af 100644
--- a/day-6/script.ts
+++ b/day-6/script.ts
@@ -2,10 +2,11 @@ import fs from "fs";
const input = fs.readFileSync("./input.txt").toString();
-const [times, distances] = input
+const [time, distance] = input
.split("\n")
.slice(0, 2)
- .map((s) => s.match(/\d+/g)?.map(Number) || []);
+ .map((s) => s.match(/\d+/g)?.join("") || "")
+ .map(Number);
function numberOfWaysToWin(time: number, record: number) {
// Solution to quadratic:
@@ -19,11 +20,6 @@ function numberOfWaysToWin(time: number, record: number) {
return wholeMax - wholeMin;
}
-const result = times
- .map((time, index) => {
- const distance = distances[index];
- return numberOfWaysToWin(time, distance);
- })
- .reduce((acc, v) => acc * v, 1);
+const result = numberOfWaysToWin(time, distance);
console.log(result);