adventofcode/2022/01/test.js

33 lines
812 B
JavaScript
Raw Normal View History

2022-12-01 16:41:34 +00:00
import * as R from "remeda";
import { test, expect } from "vitest";
import fs from "fs-extra";
2022-12-03 21:32:41 +00:00
import path from 'path';
import { expectSolution } from './main.js';
2022-12-01 16:41:34 +00:00
const split = (splitter) => (text) => text.split(splitter);
const sum = R.sumBy(R.identity);
const input = R.pipe(
2022-12-03 21:32:41 +00:00
fs.readFileSync( path.join( path.dirname(import.meta.url), "input").replace('file:',''), "utf8"),
2022-12-01 16:41:34 +00:00
split("\n\n"),
R.map((x) =>
split("\n")(x)
.map((x) => parseInt(x))
.filter(R.isNumber)
),
R.map(sum)
);
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);
});