adventofcode/2022/04/part2.js

14 lines
361 B
JavaScript
Raw Permalink Normal View History

2022-12-04 17:37:18 +00:00
import * as R from "remeda";
2022-12-04 17:42:17 +00:00
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))
);