From 68b75967b6cf407edd93b853d9505ef3e0cb89d3 Mon Sep 17 00:00:00 2001 From: Yanick Date: Sat, 3 Dec 2022 14:52:19 -0500 Subject: [PATCH] part 1 --- 2022/03/part1.js | 23 +++++++++++++++++++++++ 2022/03/part2.js | 2 ++ 2022/03/sample | 6 ++++++ 2022/03/test.js | 29 +++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 2022/03/part1.js create mode 100644 2022/03/part2.js create mode 100644 2022/03/sample create mode 100644 2022/03/test.js diff --git a/2022/03/part1.js b/2022/03/part1.js new file mode 100644 index 0000000..a7d31f2 --- /dev/null +++ b/2022/03/part1.js @@ -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 ) +); + diff --git a/2022/03/part2.js b/2022/03/part2.js new file mode 100644 index 0000000..31477e8 --- /dev/null +++ b/2022/03/part2.js @@ -0,0 +1,2 @@ +import * as R from "remeda"; + diff --git a/2022/03/sample b/2022/03/sample new file mode 100644 index 0000000..f17e726 --- /dev/null +++ b/2022/03/sample @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw diff --git a/2022/03/test.js b/2022/03/test.js new file mode 100644 index 0000000..95bdb5f --- /dev/null +++ b/2022/03/test.js @@ -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'); + }); +});