adventofcode/2022/13/part2.js
2022-12-13 12:58:27 -05:00

15 lines
393 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)
);