adventofcode/2022/03/part2.js
2022-12-03 15:26:15 -05:00

13 lines
365 B
JavaScript

import * as R from "remeda";
export const solutionPart2 = R.createPipe(
(text) => text.split("\n"),
R.filter(R.identity),
R.map((line) => line.split("")),
R.chunk(3),
R.map((group) => group.reduce((a, b) => R.intersection(a, b))),
R.map((line) => line[0].charCodeAt(0)),
R.map((code) => (code > 96 ? code - 96 : code - 38)),
R.sumBy(R.identity)
);