summaryrefslogtreecommitdiff
path: root/day-6
diff options
context:
space:
mode:
Diffstat (limited to 'day-6')
-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);