From b0fa6e8d461e3c4e42ff7a3104802707f51aa534 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Thu, 1 Dec 2022 11:41:34 -0500 Subject: [PATCH] day 1 --- 2022/01/test.js | 38 ++++++++++++++++++++++++++++++++++++++ 2022/Taskfile.yaml | 12 ++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 2022/01/test.js create mode 100644 2022/Taskfile.yaml diff --git a/2022/01/test.js b/2022/01/test.js new file mode 100644 index 0000000..a573612 --- /dev/null +++ b/2022/01/test.js @@ -0,0 +1,38 @@ +import * as R from "remeda"; +import { test, expect } from "vitest"; +import fs from "fs-extra"; + +const split = (splitter) => (text) => text.split(splitter); +const sum = R.sumBy(R.identity); +const spy = (x) => { + console.debug(x); + return x; +}; + +const input = R.pipe( + fs.readFileSync("input", "utf8"), + split("\n\n"), + R.map((x) => + split("\n")(x) + .map((x) => parseInt(x)) + .filter(R.isNumber) + ), + R.map(sum) +); + +function expectSolution(result) { + console.info(result); + return expect(result); +} + +test("part 1", () => { + const maxCalories = R.pipe(input, (calories) => Math.max(...calories)); + + expectSolution(maxCalories).toEqual(71780); +}); + +test("part 2", () => { + input.sort((a, b) => (a > b ? -1 : 1)); + + expectSolution(R.pipe(input, R.take(3), R.sumBy(R.identity))).toEqual(212489); +}); diff --git a/2022/Taskfile.yaml b/2022/Taskfile.yaml new file mode 100644 index 0000000..51b2a82 --- /dev/null +++ b/2022/Taskfile.yaml @@ -0,0 +1,12 @@ +# https://taskfile.dev + +version: '3' + +vars: + GREETING: Hello, World! + +tasks: + default: + cmds: + - echo "{{.GREETING}}" + silent: true