adventofcode/2022/04/part2.js

14 lines
361 B
JavaScript

import * as R from "remeda";
const overlapsWith = ([a1, a2], [b1, b2]) => a2 >= b1;
export const solutionPart2 = R.createPipe(
(text) => text.split("\n"),
R.filter(R.identity),
R.map((line) =>
line.split(",").map((range) => range.split("-").map((x) => parseInt(x)))
),
R.map(R.sortBy(([x]) => x)),
R.countBy(([a, b]) => overlapsWith(a, b))
);