part 1
This commit is contained in:
parent
672902f184
commit
68b75967b6
23
2022/03/part1.js
Normal file
23
2022/03/part1.js
Normal 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
2
2022/03/part2.js
Normal file
@ -0,0 +1,2 @@
|
||||
import * as R from "remeda";
|
||||
|
6
2022/03/sample
Normal file
6
2022/03/sample
Normal file
@ -0,0 +1,6 @@
|
||||
vJrwpWtwJgWrhcsFMMfFFhFp
|
||||
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
|
||||
PmmdzqPrVvPwwTWBwg
|
||||
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
|
||||
ttgJtRGJQctTZtZT
|
||||
CrZsJsPPZsGzwwsLwLmpwMDw
|
29
2022/03/test.js
Normal file
29
2022/03/test.js
Normal 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');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user