adventofcode/2022/13/part2.js

14 lines
395 B
JavaScript

import * as R from "remeda";
import { isLessThan } from "./part1";
const dividers = [[[2]],[[6]]];
export default R.createPipe(
R.flatten,
R.concat(dividers),
(packets) => packets.sort(isLessThan),
packets => packets.map( (p,i) => ({ i: i+1, divider: dividers.includes(p) }) ),
R.filter( ({divider}) => divider ),
R.map(R.prop('i')),
(v) => v.reduce((a,b)=>a*b),
);