adventofcode/2023/04/part1.js
2023-12-04 12:19:52 -05:00

29 lines
622 B
JavaScript

import * as R from "remeda";
export const slice_and_dice = R.createPipe(
(l) =>
l
.replace(/Card \d+:/, "")
.split("|")
.map((segment) => segment.split(" ").filter(R.identity)),
([winning, mine]) => {
let seen = {};
winning.forEach((n) => (seen[n] = true));
let got = mine.filter((n) => seen[n]).length;
return got;
},
(n) => (n == 0 ? 0 : Math.pow(2, n - 1))
);
export const get_lines = R.createPipe( (i) => i.split("\n"),
R.compact);
export function solution_1(input) {
return R.pipe(
input,
get_lines,
R.map(slice_and_dice),
R.sumBy(R.identity)
);
}