-
Notifications
You must be signed in to change notification settings - Fork 0
/
b.test.ts
32 lines (26 loc) · 834 Bytes
/
b.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { expect, test } from "bun:test";
function solution(input: string) {
const [time, distance] = input.split("\n").map((s) => Number(s.match(/\d+/g)?.join("")));
const s = (v: number, t: number): number => v * t;
let counter = 0;
for (let j = 1; j < time; j++) {
if (s(j, time - j) > distance) {
counter += 1;
}
}
return counter;
}
test("example", async () => {
const file = Bun.file("./06/example.txt");
const input = await file.text();
const actual = solution(input);
const expected = 71503;
expect(actual).toBe(expected);
});
test("puzzle input", async () => {
const file = Bun.file("./06/input.txt");
const input = await file.text();
const actual = solution(input);
const expected = 42515755;
expect(actual).toBe(expected);
});