-
Notifications
You must be signed in to change notification settings - Fork 0
/
a.test.ts
40 lines (34 loc) · 999 Bytes
/
a.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
33
34
35
36
37
38
39
40
import { expect, test } from "bun:test";
function solution(input: string) {
const words = input.split(",").map((word) => word.split(""));
let ans = 0;
for (const word of words) {
let value = 0;
for (const ch of word) {
value += ch.charCodeAt(0);
value *= 17;
value %= 256;
}
ans += value;
}
return ans;
}
test("example-1", async () => {
const actual = solution("HASH");
const expected = 52;
expect(actual).toBe(expected);
});
test("example-2", async () => {
const file = Bun.file(`${import.meta.dir}/example.txt`);
const input = await file.text();
const actual = solution(input);
const expected = 1320;
expect(actual).toBe(expected);
});
test("puzzle input", async () => {
const file = Bun.file(`${import.meta.dir}/input.txt`);
const input = await file.text();
const actual = solution(input);
const expected = 511416;
expect(actual).toBe(expected);
});