diff --git a/day-3/day3.ts b/day-3/day3.ts index d763eb8..e8948b9 100644 --- a/day-3/day3.ts +++ b/day-3/day3.ts @@ -3,16 +3,16 @@ import * as R from "remeda"; const regex = new RegExp(/mul\((\d{1,3},\d{1,3}?)\)/g); export function day3(input: string) { - const matches = input.matchAll(regex); - const numberPairs = []; - for (const match of matches) { - numberPairs.push(match[1].split(",").map((v) => Number.parseInt(v, 10))); - } - return R.pipe( - numberPairs, - R.map(([a, b]) => a * b), - R.sum, - ) as unknown as number; + return R.sum( + input + .matchAll(regex) + .map((match) => { + // match[1] looks like "2,4" + const [a, b] = match[1].split(",").map((v) => Number.parseInt(v, 10)); + return a * b; + }) + .toArray(), + ); } export function day3part2(input: string) {