21 lines
656 B
JavaScript
21 lines
656 B
JavaScript
import * as R from "remeda";
|
|
import fs from "fs-extra";
|
|
import path from "path";
|
|
|
|
export const readFile = (year, day, file) =>
|
|
fs.readFileSync(path.join(year, day, file), "utf8");
|
|
|
|
export const sample = readFile("2022", "03", "sample");
|
|
export const puzzleInput = readFile("2022", "03", "input");
|
|
|
|
export const solutionPart1 = R.createPipe(
|
|
(text) => text.split("\n"),
|
|
R.filter(R.identity),
|
|
R.map((line) => line.split("")),
|
|
R.map((line) => [line, line.splice(line.length / 2)]),
|
|
R.map((line) => R.intersection(...line)),
|
|
R.map((line) => line[0].charCodeAt(0)),
|
|
R.map((code) => (code > 96 ? code - 96 : code - 38)),
|
|
R.sumBy(R.identity)
|
|
);
|