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) ); }