This commit is contained in:
Yanick 2022-12-03 14:52:19 -05:00
parent 672902f184
commit 68b75967b6
4 changed files with 60 additions and 0 deletions

23
2022/03/part1.js Normal file
View File

@ -0,0 +1,23 @@
import * as R from "remeda";
import fs from 'fs-extra';
import path from 'path';
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 )
);

2
2022/03/part2.js Normal file
View File

@ -0,0 +1,2 @@
import * as R from "remeda";

6
2022/03/sample Normal file
View File

@ -0,0 +1,6 @@
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw

29
2022/03/test.js Normal file
View File

@ -0,0 +1,29 @@
import { test, expect, describe } from "vitest";
import {
solutionPart1,
sample,
puzzleInput,
} from "./part1.js";
import { solutionPart2 } from "./part2.js";
function expectSolution(result) {
console.info(result);
return expect(result);
}
describe("part 1", () => {
test( 'sample', () => {
console.log(JSON.stringify(solutionPart1(sample)));
expectSolution(solutionPart1(sample)).toEqual(157)
});
test("solution", () => {
expectSolution(solutionPart1(puzzleInput)).toEqual('TODO');
});
});
describe("part 2", () => {
test.todo("solution", () => {
expectSolution(solutionPart2(puzzleInput)).toEqual('TODO');
});
});