Skip to content

build: bun migration #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
.DS_Store
*.txt
puzzle.txt
9 changes: 9 additions & 0 deletions 2024/07/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
190: 10 19
3267: 81 40 27
83: 17 5
156: 15 6
7290: 6 8 6 15
161011: 16 10 13
192: 17 8 14
21037: 9 7 18 13
292: 11 6 16 20
25 changes: 25 additions & 0 deletions 2024/07/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect, describe, test } from "bun:test";
import { part1, part2 } from ".";
import { getInputs } from "../../utils/get-inputs";

const { exampleInput, puzzleInput } = await getInputs("2024/07");

describe("part 1", () => {
test("example", () => {
expect(part1(exampleInput)).toBe(3749);
});

test("puzzle", () => {
expect(part1(puzzleInput)).toBe(3312271365652);
});
});

describe("part 2", () => {
test("example", () => {
expect(part2(exampleInput)).toBe(11387);
});

test("puzzle", () => {
expect(part2(puzzleInput)).toBe(509463489296712);
});
});
50 changes: 26 additions & 24 deletions 2024/07/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { getPuzzle } from "../../utils";
import { timePart1, timePart2 } from "../../utils/time-part";

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

const equations = puzzleInput.split("\n").map((row) => {
const [testValue, numbers] = row.split(": ");
return {
testValue: parseInt(testValue),
numbers: numbers.split(" ").map((n) => parseInt(n)),
};
});
};

return {
testValue: parseInt(testValue),
numbers: numbers.split(" ").map((n) => parseInt(n)),
};
});

// Part 1
(() => {
console.time("part 1");
export const part1 = timePart1((input: string) => {
let total = 0;
const equations = parseInput(input);

const compare = ({ numbers, testValue }: (typeof equations)[number]) => {
const compare = ({
numbers,
testValue,
}: (typeof equations)[number]): boolean => {
if (numbers.length === 1) {
return testValue === numbers[0];
}
Expand Down Expand Up @@ -48,16 +50,17 @@ const equations = puzzleInput.split("\n").map((row) => {
}
}

console.log("part 1 total ::", total);
console.timeEnd("part 1");
})();
return total;
});

// Part 2
(() => {
console.time("part 2");
export const part2 = timePart2((input: string) => {
let total = 0;
const equations = parseInput(input);

const compare = ({ numbers, testValue }: (typeof equations)[number]) => {
const compare = ({
numbers,
testValue,
}: (typeof equations)[number]): boolean => {
if (numbers.length === 1) {
return testValue === numbers[0];
}
Expand Down Expand Up @@ -89,6 +92,5 @@ const equations = puzzleInput.split("\n").map((row) => {
}
}

console.log("part 2 total ::", total);
console.timeEnd("part 2");
})();
return total;
});
12 changes: 12 additions & 0 deletions 2024/08/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
............
........0...
.....0......
.......0....
....0.......
......A.....
............
............
........A...
.........A..
............
............
25 changes: 25 additions & 0 deletions 2024/08/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect, describe, test } from "bun:test";
import { part1, part2 } from ".";
import { getInputs } from "../../utils/get-inputs";

const { exampleInput, puzzleInput } = await getInputs("2024/08");

describe("part 1", () => {
test("example", () => {
expect(part1(exampleInput)).toBe(14);
});

test("puzzle", () => {
expect(part1(puzzleInput)).toBe(269);
});
});

describe("part 2", () => {
test("example", () => {
expect(part2(exampleInput)).toBe(34);
});

test("puzzle", () => {
expect(part2(puzzleInput)).toBe(949);
});
});
40 changes: 20 additions & 20 deletions 2024/08/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { getPuzzle } from "../../utils";
import { timePart1, timePart2 } from "../../utils/time-part";

const puzzleInput = getPuzzle(__dirname).trim();
const parseInput = (input: string) =>
input.split("\n").map((row) => row.split(""));

const map = puzzleInput.split("\n").map((row) => row.split(""));
const measureMap = (map: ReturnType<typeof parseInput>) => {
const WIDTH = map[0].length;
const HEIGHT = map.length;

const WIDTH = map[0].length;
const HEIGHT = map.length;

// Part 1
(() => {
console.time("part 1");
return { WIDTH, HEIGHT };
};

export const part1 = timePart1((input: string) => {
const map = parseInput(input);
const { HEIGHT, WIDTH } = measureMap(map);
const antennas = new Map<string, Set<string>>();

for (let y = 0; y < HEIGHT; y++) {
Expand All @@ -22,7 +24,7 @@ const HEIGHT = map.length;
}

if (antennas.has(cell)) {
antennas.get(cell).add(`${x},${y}`);
antennas.get(cell)!.add(`${x},${y}`);
} else {
antennas.set(cell, new Set<string>([`${x},${y}`]));
}
Expand Down Expand Up @@ -83,13 +85,12 @@ const HEIGHT = map.length;
}
}

console.log("part 1 antinode count ::", antinodes.size);
console.timeEnd("part 1");
})();
return antinodes.size;
});

// Part 2
(() => {
console.time("part 2");
export const part2 = timePart2((input: string) => {
const map = parseInput(input);
const { HEIGHT, WIDTH } = measureMap(map);
const antennas = new Map<string, Set<string>>();

for (let y = 0; y < HEIGHT; y++) {
Expand All @@ -101,7 +102,7 @@ const HEIGHT = map.length;
}

if (antennas.has(cell)) {
antennas.get(cell).add(`${x},${y}`);
antennas.get(cell)!.add(`${x},${y}`);
} else {
antennas.set(cell, new Set<string>([`${x},${y}`]));
}
Expand Down Expand Up @@ -198,6 +199,5 @@ const HEIGHT = map.length;
}
}

console.log("part 2 antinode count ::", antinodes.size);
console.timeEnd("part 2");
})();
return antinodes.size;
});
1 change: 1 addition & 0 deletions 2024/09/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2333133121414131402
25 changes: 25 additions & 0 deletions 2024/09/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect, describe, test } from "bun:test";
import { part1, part2 } from ".";
import { getInputs } from "../../utils/get-inputs";

const { exampleInput, puzzleInput } = await getInputs("2024/09");

describe("part 1", () => {
test("example", () => {
expect(part1(exampleInput)).toBe(1928);
});

test("puzzle", () => {
expect(part1(puzzleInput)).toBe(6258319840548);
});
});

describe("part 2", () => {
test("example", () => {
expect(part2(exampleInput)).toBe(2858);
});

test("puzzle", () => {
expect(part2(puzzleInput)).toBe(6286182965311);
});
});
26 changes: 11 additions & 15 deletions 2024/09/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { getPuzzle } from "../../utils";
import { timePart1, timePart2 } from "../../utils/time-part";

const puzzleInput = getPuzzle(__dirname).trim();
const diskMap = puzzleInput.split("");
const parseInput = (input: string) => input.split("");

// Part 1
(() => {
console.time("part 1");
export const part1 = timePart1((input: string) => {
const diskMap = parseInput(input);
let representation = "";

for (let i = 0; i < diskMap.length; i++) {
Expand All @@ -26,7 +25,7 @@ const diskMap = puzzleInput.split("");
let lastFileBlockIndex = representationArr.findLastIndex((e) => e !== ".");

while (lastFileBlockIndex > firstFreeSpaceBlockIndex) {
const lastEntry = representationArr.pop();
const lastEntry = representationArr.pop()!;

if (lastEntry !== ".") {
representationArr[firstFreeSpaceBlockIndex] = lastEntry;
Expand All @@ -50,13 +49,11 @@ const diskMap = puzzleInput.split("");
}
}

console.log("part 1 checksum ::", checksum);
console.timeEnd("part 1");
})();
return checksum;
});

// Part 2
(() => {
console.time("part 2");
export const part2 = timePart2((input: string) => {
const diskMap = parseInput(input);
let representation = "";

for (let i = 0; i < diskMap.length; i++) {
Expand Down Expand Up @@ -145,6 +142,5 @@ const diskMap = puzzleInput.split("");
}
}

console.log("part 2 checksum ::", checksum);
console.timeEnd("part 2");
})();
return checksum;
});
21 changes: 21 additions & 0 deletions 2024/15/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
##########
#..O..O.O#
#......O.#
#.OO..O.O#
#[email protected].#
#O#..O...#
#O..O..O.#
#.OO.O.OO#
#....O...#
##########

<vv>^<v^>v>^vv^v>v<>v^v<v<^vv<<<^><<><>>v<vvv<>^v^>^<<<><<v<<<v^vv^v>^
vvv<<^>^v^^><<>>><>^<<><^vv^^<>vvv<>><^^v>^>vv<>v<<<<v<^v>^<^^>>>^<v<v
><>vv>v^v^<>><>>>><^^>vv>v<^^^>>v^v^<^^>v^^>v^<^v>v<>>v^v^<v>v^^<^^vv<
<<v<^>>^^^^>>>v^<>vvv^><v<<<>^^^vv^<vvv>^>v<^^^^v<>^>vvvv><>>v^<<^^^^^
^><^><>>><>^^<<^^v>>><^<v>^<vv>>v>>>^v><>^v><<<<v>>v<v<v>vvv>^<><<>^><
^>><>^v<><^vvv<^^<><v<<<<<><^v<<<><<<^^<v<^^^><^>>^<v^><<<^>>^v<v^v<v^
>^>>^v>vv>^<<^v<>><<><<v<<v><>v<^vv<<<>^^v^>^^>>><<^v>>v^v><^^>>^<>vv^
<><^^>^^^<><vvvvv^v<v<<>^v<v>v<<^><<><<><<<^^<<<^<<>><<><^^^>^^<>^>v<>
^^>vv<^v^v<vv>^<><v<^v>^^^>>>^^vvv^>vvv<>>>^<^>>>>>^<<^v>^vvv<>^<><<v>
v^^>>><<^^<>>^v^<v^vv<>v^<<>^<^v^v><^<<<><<^<v><v<>vv>>v><v^<vv<>v^<<^
25 changes: 25 additions & 0 deletions 2024/15/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect, describe, test } from "bun:test";
import { part1, part2 } from ".";
import { getInputs } from "../../utils/get-inputs";

const { exampleInput, puzzleInput } = await getInputs("2024/15");

describe("part 1", () => {
test("example", () => {
expect(part1(exampleInput)).toBe(10092);
});

test("puzzle", () => {
expect(part1(puzzleInput)).toBe(1563092);
});
});

describe("part 2", () => {
test("example", () => {
expect(part2(exampleInput)).toBe(9021);
});

test("puzzle", () => {
expect(part2(puzzleInput)).toBe(1582688);
});
});
Loading