adventofcode/2023/04/part1.js

27 lines
619 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 function solution_1(input) {
return R.pipe(
input,
i => i.split("\n"),
R.compact,
R.map(
slice_and_dice
),
R.sumBy(R.identity)
)
}