2022-12-13 17:58:12 +00:00
|
|
|
import * as R from "remeda";
|
|
|
|
import { isLessThan } from "./part1";
|
|
|
|
|
2022-12-13 17:58:27 +00:00
|
|
|
const dividers = [[[2]], [[6]]];
|
2022-12-13 17:58:12 +00:00
|
|
|
export default R.createPipe(
|
2022-12-13 17:58:27 +00:00
|
|
|
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)
|
2022-12-13 17:58:12 +00:00
|
|
|
);
|