adventofcode/2022/03/part1.js

21 lines
656 B
JavaScript
Raw Normal View History

2022-12-03 19:52:19 +00:00
import * as R from "remeda";
2022-12-03 20:26:15 +00:00
import fs from "fs-extra";
import path from "path";
2022-12-03 19:52:19 +00:00
2022-12-04 17:42:17 +00:00
export const readFile = (year, day, file) =>
2022-12-03 20:26:15 +00:00
fs.readFileSync(path.join(year, day, file), "utf8");
2022-12-03 19:52:19 +00:00
2022-12-03 20:26:15 +00:00
export const sample = readFile("2022", "03", "sample");
export const puzzleInput = readFile("2022", "03", "input");
2022-12-03 19:52:19 +00:00
export const solutionPart1 = R.createPipe(
2022-12-03 20:26:15 +00:00
(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)
2022-12-03 19:52:19 +00:00
);