Skip to content

Commit ade07ea

Browse files
committed
build: initial bun migration
1 parent 499a269 commit ade07ea

File tree

8 files changed

+104
-1892
lines changed

8 files changed

+104
-1892
lines changed

2024/07/index.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { expect, describe, test } from "bun:test";
2+
import { part1, part2 } from ".";
3+
import { getInputs } from "../../utils/get-inputs";
4+
5+
const { exampleInput, puzzleInput } = await getInputs("2024/07");
6+
7+
describe("part 1", () => {
8+
test("example", () => {
9+
expect(part1(exampleInput)).toBe(3749);
10+
});
11+
12+
test("puzzle", () => {
13+
expect(part1(puzzleInput)).toBe(3312271365652);
14+
});
15+
});
16+
17+
describe("part 2", () => {
18+
test("example", () => {
19+
expect(part2(exampleInput)).toBe(11387);
20+
});
21+
22+
test("puzzle", () => {
23+
expect(part2(puzzleInput)).toBe(509463489296712);
24+
});
25+
});

2024/07/index.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
import { getPuzzle } from "../../utils";
1+
import { timePart1, timePart2 } from "../../utils/time-part";
22

3-
const puzzleInput = getPuzzle(__dirname).trim();
3+
const parseInput = (input: string) => {
4+
return input.split("\n").map((row) => {
5+
const [testValue, numbers] = row.split(": ");
46

5-
const equations = puzzleInput.split("\n").map((row) => {
6-
const [testValue, numbers] = row.split(": ");
7+
return {
8+
testValue: parseInt(testValue),
9+
numbers: numbers.split(" ").map((n) => parseInt(n)),
10+
};
11+
});
12+
};
713

8-
return {
9-
testValue: parseInt(testValue),
10-
numbers: numbers.split(" ").map((n) => parseInt(n)),
11-
};
12-
});
13-
14-
// Part 1
15-
(() => {
16-
console.time("part 1");
14+
export const part1 = timePart1((input: string) => {
1715
let total = 0;
16+
const equations = parseInput(input);
1817

19-
const compare = ({ numbers, testValue }: (typeof equations)[number]) => {
18+
const compare = ({
19+
numbers,
20+
testValue,
21+
}: (typeof equations)[number]): boolean => {
2022
if (numbers.length === 1) {
2123
return testValue === numbers[0];
2224
}
@@ -48,16 +50,17 @@ const equations = puzzleInput.split("\n").map((row) => {
4850
}
4951
}
5052

51-
console.log("part 1 total ::", total);
52-
console.timeEnd("part 1");
53-
})();
53+
return total;
54+
});
5455

55-
// Part 2
56-
(() => {
57-
console.time("part 2");
56+
export const part2 = timePart2((input: string) => {
5857
let total = 0;
58+
const equations = parseInput(input);
5959

60-
const compare = ({ numbers, testValue }: (typeof equations)[number]) => {
60+
const compare = ({
61+
numbers,
62+
testValue,
63+
}: (typeof equations)[number]): boolean => {
6164
if (numbers.length === 1) {
6265
return testValue === numbers[0];
6366
}
@@ -89,6 +92,5 @@ const equations = puzzleInput.split("\n").map((row) => {
8992
}
9093
}
9194

92-
console.log("part 2 total ::", total);
93-
console.timeEnd("part 2");
94-
})();
95+
return total;
96+
});

bun.lockb

22.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)