2 changed files with 50 additions and 0 deletions
@ -0,0 +1,38 @@
@@ -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); |
||||
}); |
Loading…
Reference in new issue