diff --git a/2024/day-16/day16.test.ts b/2024/day-16/day16.test.ts new file mode 100644 index 0000000..808225a --- /dev/null +++ b/2024/day-16/day16.test.ts @@ -0,0 +1,40 @@ +import { expect, test } from "bun:test" +import * as path from "node:path" +import { part1, part2 } from "./day16.ts" + +test("day 16, part 1", async () => { + const testInput = await Bun.file( + path.resolve(__dirname, "test-input.txt"), + ).text() + const input = await Bun.file(path.resolve(__dirname, "input.txt")).text() + + console.log("\n\n") + + // const testResult = part1(testInput) + // console.log("Test data:", testResult) + // expect(testResult).toEqual(7036) + + const finalResult = part1(input) + console.log("Full data:", finalResult) + expect(finalResult).toEqual(0) + + console.log("\n\n") +}) + +test("day 16, part 2", async () => { + const testInput = await Bun.file( + path.resolve(__dirname, "test-input.txt"), + ).text() + const input = await Bun.file(path.resolve(__dirname, "input.txt")).text() + + const testResult = part2(testInput) + console.log("\n\n") + console.log("Test data:", testResult) + expect(testResult).toEqual(0) + + // const finalResult = part2(input); + // console.log("Full data:", finalResult); + // expect(finalResult).toEqual(0); + + console.log("\n\n") +}) diff --git a/2024/day-16/day16.ts b/2024/day-16/day16.ts new file mode 100644 index 0000000..854830d --- /dev/null +++ b/2024/day-16/day16.ts @@ -0,0 +1,15 @@ +import { solveMaze } from "./maze.ts" + +export function part1(input: string) { + const grid = parseInput(input) + return solveMaze(grid) +} + +export function part2(input: string) { + return 0 +} + +function parseInput(input: string) { + const lines = input.split("\n") + return lines.map((l) => l.split("")) +} diff --git a/2024/day-16/input.txt b/2024/day-16/input.txt new file mode 100644 index 0000000..f90786f --- /dev/null +++ b/2024/day-16/input.txt @@ -0,0 +1,141 @@ +############################################################################################################################################# +#.#.....#...#...........#...........#.....#.......#.......#.....#...............#.........#.....#...#.....#.......#........................E# +#.#.###.#.#.#.###.###.#.###.#.###.###.#.#.#.#.###.#####.#.#.###.###.###.#####.###.#####.#.#.#.#.###.#.#.#.###.###.#.###.#.#.###.#######.###.# +#.....................#.....#.#...#...#.#.#.#...#...#...#.#...#...#.#.......#.....#...#.#.#.#.#...#...#.#...#...#.#...#.#.#.#...#.....#.....# +#.#.#.#########.#.#.###########.#.#.###.#.#.###.###.#.###.###.###.#.###.#.#.#########.#.#.#.#.###.#.###.###.###.#.###.#.#.#.#.#.#.#.#.#.##### +#.#.#.......#...#...#...................#.#...#...#...#.#.....#.#.#...#.#.#.....#.....#.#.#.#...#.#...#...#.....#.#...#...#...#...#.#.#...#.# +#.#.#.#####.#.###.#.#.#.#.#.#.###.#####.###.#####.#####.#######.#.###.#.#.#####.###.#.#.###.###.#.#####.#.#######.#.###########.###.#####.#.# +#.#.#...#...#.#...#.#.#...#.#...#.#.....#.........................#...#.#...#.#.....#.#.....#...#...............#.#.#...#.......#...#.....#.# +#.#.###.#####.#.#.#.#.#####.###.#.#.#####.#.#.#####.###.#########.#.###.###.#.###.###########.#.#######.###.#.#.#.#.#.#.#.#.###.#.#.#.#####.# +#.#.....#.....#.#.#.#.#...#...#...#.........#.#...#...#...........#...#...#.#.#...#...........#.........................#.#.#.#...#.#.......# +#.#.###.#.#####.###.#.#.#.#.#.#.#.#########.#.###.###.#########.#####.#####.#.#.###.###########.###.#.#.#####.#####.###.###.#.#.###.#######.# +#.............#.....#.#.#.#.#.#.#.....#...#...#.....#.#.......#.....#.....#.#...#.#...#...#...#...#...#.....#.#.......#.....................# +#.#.#####.#.#.#######.#.###.#.#.#.###.#.#.#.###.#####.#.#####.#.#########.#.#.###.###.#.###.#.#.#.###.#.#.#.#.###########.#.#.#.#.#.#.###.### +#...#...#...#.#.........#...#.....#...#.#...#.......#.#...#.#.#.......#.#...#.#.....#.#.#...#...#.#...#.#.#.#.#.......#...#.#...#.....#...#.# +#.#.#.#.###.#.#.#########.#####.#.#.###.#.#.#######.#.#.#.#.#.#.###.#.#.#.###.#####.#.#.#.#####.#.#.###.#.#.#.#.#####.#.###.###.#.#####.###.# +#.#...#.....#.#...#.....#...#.......#.....#...#.....#.#...#...#...#.#.....#.........#.#...#.......#.#...#.#.#...#...#.#...#.....#.#.........# +#.#.#######.#.###.#.#.#.###.#.###.###.#####.#.#.###.#.###.#.#######.#####.#.###.#####.#.###.#######.#####.#.#####.#.#.###.#.###.###.#.#.#.#.# +#.#...#.....#...#...#.#...#.....#...#.......#.#...#.#.....#.......#.#...#.#...#.#.....#.#...#.....#.......#.#.....#.#.....#...#.#...#.#.#.#.# +#.#.###.###.#.#.#.#.#.###.#####.#.#.#########.#.#.###############.#.#.#.#####.#.#.#####.#.###.###.#########.#####.#.#########.#.#.###.#.#.#.# +#.....#...#...#.....#...#...#.#.#.#...........#.#...#.....#.......#...#.....#...#.#...#.#.#.....#.........#.....#.#.#.....#...#...#.#...#.#.# +#.###.###.#.#.#.###.###.###.#.#.#.###.#.#######.###.#.#.#.#.#.#.###.#####.#.###.#.#.###.#.#.#######.#.#.#######.#.#.#.###.#.#######.#######.# +#...#.....#.#.#.#.......#.#.#...#...#.#.#.........#...#.....#.#.#.......#.#...#.#.#.#...#...#.....#...#.........#.#.#...#.#.#.....#.......#.# +#.#.#####.#.#.#.#.#####.#.#.#.###.#.###.#.###########.#.###.#.#.#.#####.#.#.#.#.#.#.#.#####.#.###.#.#.#######.#.#.###.###.#.###.#.#.#####.#.# +#.#...#...#.#.#.#.#.......#.#.#...#.#...#.#.....#...#.#.#.....#.........#.#.#...#.#.#.#.....#.#.#...#.........#...#...#...#.....#...#...#...# +#.#.###.###.#.###.#.#.#.###.#.#####.#.###.#####.#.#.###.#.#####.#.#####.#.#.#####.#.#.#.#.###.#.#####.###.#####.###.###.#############.#.#.#.# +#.#.#...#...#.....#.#.#.#...#.#.....#.#.....#...#.#.....#.....#...#...#.#...#...#.#.#.#.#.#...#.....#...#.....#.#...#.#.......#.....#.#...#.# +#.###.###.###.#####.#.###.###.#.###.#.#####.#.###.#####.#########.#.###.#####.#.#.#.#.###.#.###.###.#.#.###.#.#.#.###.#####.###.#.###.#.#.#.# +#.......#.....#.....#...#.#...#...#.#...#.....#...#.....#...#.....#.........#.#...#.#.....#.#...#.#...#.#...#...#.........#.....#.....#.#.#.# +#.#.###.#####.#.#.###.#.#.#.#.###.#####.#.#####.###.#####.#.#.###########.###.#####.###.###.#.###.#####.#.#.#############.#############.#.#.# +#...#...#...#.#.#...#.#...#.....#...#...#.#.#...#...#.....#...#.......#.....#.#.#.......#...#.........#.....#...........#.#...#.......#.....# +#.###.#.#.#.#.#.###.#.###.#####.###.#.###.#.#.###.###.#############.#.#.#.#.#.#.#.#####.#.###########.#####.#.#######.#.#.#.#.#######.###.### +#.#...#.#...#...#...#.........#.....#...#...#.#.....#...#.....#.....#.#...#.#.....#.....#.........#...#...#.#.#.#.....#.#...#.......#.......# +#.#.#.#.#.###.#.#.###########.#####.###.#####.#.#######.#.###.#.#####.#.#.#.#.###.#.###.###.#####.#.###.#.###.#.#.#####.###########.#.#.#.### +#.#.#.#...#...#.#.....#...#.....#.....#...#...#.#...#...#...#...#.#...#.#.#.#...#.#.#.#.......#.#.#.#...#.......#.#.#...#...#.....#.#.#.....# +#.###.#.###.#.#######.###.#.#.#.#.#######.#.###.#.#.#.###.#.###.#.#.###.#.#.#.#.###.#.###.###.#.#.###.###########.#.#.#.#.#.#.#.###.#.###.#.# +#...#.#.#...#.......#...#.#.#...#.#.......#...#.#.#.#.....#.....#.......#.#...#.#...#.#...#.#...#.....#.#.....#...#.#.#...#.#.#.#...#.#...#.# +###.#.###.#########.###.#.#.#.#.#.#.#######.#.###.#.#####.#.###.###.###.#.#.#.#.#.###.#.###.###.#######.#.#.###.###.#.###.#.#.#.#.###.###.#.# +#.#...#...#...#.....#...#...#.#.#.#.#...#...#.....#.....#.#...#...#...#.#.#.#.#...#...#.#...#.#...#...#...#.#...#.....#...#.#.#.#...#.....#.# +#.###.#.#####.#.#####.###.###.#.#.#.#.#.#.###########.#.#.#######.###.#.#.#.#.#####.#.#.#.#.#.###.#.###.###.#.###.#####.###.#.#####.#####.#.# +#.....#.#.....#.#.....#...#...#...#.#.#.#...#.......#.#...#...#...#.#.#.#.#...#...#.#.#.#.#...#...#.......#.#.#.#.......#.................#.# +#.#####.#.#.#.#.###.###.#.#.#######.#.#.###.#.#####.#####.#.#.#.###.#.###.#.#.#.#.#.#.#.#.#####.#####.#####.#.#.#.#########.###.#####.###.#.# +#.#.....#.#.#.#.....#.#...#.#...#...#.#.#...#...#...#...#...#.....#.......#.#.#.#.#.#.#.#...#...#...#.#...#.#.#...#...........#.#.......#...# +#.#.#.#####.#.#.#####.#.###.#.#.#.###.#.#.#####.#.###.#.#####.###.#########.#.#.#.###.#.#.#.#.###.#.#.#.#.#.#.#####.#########.#.#########.### +#.#.#.#...#.#.#.......#.#...#.#.#.....#.#.#.#...#.....#...#.#...#...#.......#...#.#...#.#.#.......#.#.#.....#.#.....#.......#.#.....#...#...# +#.#.###.#.#.###.#####.#.#.###.#.#######.#.#.#.#.#########.#.###.#.#.###.#########.#.#.#.#####.#####.###.#####.#.###########.#.#.###.#.#.#.#.# +#.#.#...#.#.....#...#...#...#.#.#...#...#...#.#.#...#.#...#...#.#.#...#.#.......#...#.#.#...#.#...#.#...#...#...#.........#.#.....#...#...#.# +#.#.#.###.#.#####.#########.#.#.#.#.#.#.###.#.###.#.#.#.#####.#.#####.#.#.#.###.#####.#.#.#.###.#.#.#.###.#.###.#.#.#####.#.###.#.#######.#.# +#...#.#...#...#.......#.....#.#.#.#...#.#...#.....#.#...#.....#.......#.#.#...#.......#...#.....#.#.#.#...#...#.#.#.#.....#...#...#.....#.#.# +#.###.#.#.###.#####.###.#####.#.#.#####.#.#.#######.#.###.#.###########.#.###.#######.#.#########.#.#.#.#####.#.###.#.#######.#.#.###.#.#.#.# +#...#.#.....#.#...#...#.#.....#.#.......#.#.........#.#...#.#.......#...#.#.#...#.....#.......#...#...#.#...#.#.....#.........#.#.....#.#.#.# +#.#.#.#####.#.#.#.###.#.#.#####.#####.#.#.###########.###.###.#.#.#.#.###.#.###.#####.###.#####.#.#####.#.#.#.#########.#.#.###.#.#######.#.# +#.#.#.#...#.#.#.#...#...#.....#...#.#.#.#...#.......#...#.........#.#.#.#.....#.....#...#.#...#.#.#.......#.#...#.....#.#.#...#...........#.# +###.#.#.#.#.#.#.###.#.#######.###.#.#.#####.#.#####.###.#######.#.###.#.#####.#####.###.#.#.#.#.#.#.#.#####.###.#.###.#.#####.#.#########.#.# +#...#.#.........#...#.........#.....#.....#.#.#...#...#.......#.#.....#...........#...#.#.#.#.#.#.#.#...#.#.#...#...#.#...#...#.............# +#.###.#.#.#.#####.#####.###########.#####.#.###.#.#.#########.###.#.#.###########.###.#.###.#.#.###.#.#.#.#.#.#####.#.###.#.###.#.#######.#.# +#.......#.#...#...#.....#...#...#.#.#...#.#.....#.#.#.........#.....#.......#...#.#.#.#.#...#...#...#.#.#...#.#.....#...#.#.#...#.#.....#.#.# +#####.#.###.#.#.###.#.#.#.#.#.#.#.#.###.#.#####.#.#.#.#####.###.###.#######.#.#.#.#.#.#.#.#####.#.###.#.#####.#.#.#######.#.#.#.#.#.###.#.#.# +#...#.#...#.#.#.#...#.#.#.#.#.#.#...#...#.#...#...#.#.#.....#...#.#...#.....#.#.#.#.#.#.#.....#.#...#.#.#.....#.#.........#...#.#.#.#.#.#.#.# +#.#.###.#.###.#.###.#.###.#.#.#.#.###.#.#.#.#.#.###.#.###.#.###.#.###.#####.#.###.#.#.#.###.#.###.###.#.#.#####.#.#########.###.#.#.#.#.#.#.# +#.#.....#...#.#.....#.....#.#.#.#.....#.#.....#...#.......#.#...#...#.....#.#.......#.#.....#.#...#...#...#...#.#.........#.....#...#.#.#...# +#.#########.#.#############.#.#.#############.###.#.#######.#.###.#.#####.#.#######.#.#.###.#.#.###.#######.#.#.#.#######.#####.###.#.#.#.### +#...#.....#...#.....#.......#.#.#.............#.#.#.#...#.....#...#.....#.#.....#...#.#.#...#...#...#.......#.#.#.#...#...#.........#.#.#.#.# +###.#.###.#####.###.#.#.#####.#.#.###########.#.#.###.#.###########.###.#.#####.#####.#.#.###.###.###.###.#####.#.#.#.#.#######.###.#.#.#.#.# +#...#.#.....#.....#.#.........#.#...#.#.....#...#...#.#.#.........#.#...#...#.........#.#.#...#...#.#.#.#.......#.#...........#...#.#.#.#...# +#.###.#.###.#.###.#############.#.#.#.#.###.###.###.#.#.#.#######.#.#######.###########.#.###.#.###.#.#.#########.#.#########.###.#.#.#.#.#.# +#...#.#...#.#.#.#.#...........#.#.#.#.#.#...........#.#...#.....#.#.......#...#...#.....#...#.#.#...#...#.........#.....#...#...#.#...#.#.#.# +#.#.#####.###.#.#.#.###.#####.#.###.#.#.#.###.#.#.###.#####.###.#.#####.#.###.###.#.###.###.#.#.###.###.#.#.#######.###.#.#.###.#.#.#.#.#.#.# +#.#.....#...#...#...#.#...#...#.....#.#.#.#...#.#.....#...#...#.#.....#.#...#.#...#...#...#.#.#...#.#...#.#...#...#...#...#...#.#.....#.#...# +#.#####.#.#.###.#####.#.#.#.#########.#.#.#####.#######.#.#.###.#####.###.#.#.#.#####.###.#.#.###.#.#.#######.#.#####.#######.#.###.#.#.#.### +#.....#.#.#.....#.....#...#.......#.....#.........#.....#...#...#...#...#.#.#.#...#...#...#.#...#.#.#.#.......#.#.....#.....#.#.....#.#.....# +#####.#.#.#######.###.#.###########.#############.#.#######.#.#.#.#.###.#.###.#.#.#.###.###.#####.#.#.#.###.###.#.#####.#.###.#.###.#######.# +#.#...#.#.....#.....#.#...........#.#...#.....#...#...#.....#.#.#.#...#.#.....#.#...#.#.....#.....#.#.#...#...#...#.....#.#.......#.....#...# +#.#.###.#####.#######.###########.#.#.#.#.###.#.#####.#.###.#.###.###.###.#####.#####.#######.#####.#.###.#.#.#.#####.#.#.#.###.###.###.#.### +#...#...#.#...#.........#.........#.#.#.#.#.#.#.#.....#...#.#...#.........#.#...#.......#.....#.....#.#...#.#...#...#...#.#.........#...#...# +#####.###.#.###.#######.#.#######.#.#.###.#.#.#.#.#.###.#.#.###.###.#.###.#.#.###.#######.#.###.###.#.#.#####.#.#.#.#####.#####.###.#.#####.# +#...#.#...#.....#...#...#...#.....#.#...#...#.#.#.....#.#.#.#.#...#.#.#...#.#...#.........#.#.....#.#.#.#...#.....#...#...........#.#.....#.# +#.#.#.#.#.#.#####.#.#.#####.#######.###.###.#.#######.#.#.#.#.###.#.#.#.###.###.###########.#.###.###.#.#.#.#########.#.#######.###.#####.#.# +#.#...#.#.#.....#.#.#.#...#.......#...#...#.#.#.......#...#.#...#...#...#...#.#.............#.#...#...#...#.....#...#.#.....#.....#.....#.#.# +#.#####.#.#.#.###.#.#.###.#######.###.###.#.#.#.#######.###.#.###########.#.#.#################.###.#####.#####.#.###.#####.#.#.#.#.#.#.#.#.# +#.#...#.#.#.#.....#.#.....#.....#.........#.#.#.#.......#.....#.........#.#.....#.........#.........#...#.....#.#...#.......#...#.#.#.#.#.#.# +#.#.#.###.#.#######.#####.###.#.###########.#.#.#.#####.#######.#####.#.#.#######.#######.#.#.###.###.#.#######.#.#.###.#######.#.#.#.###.#.# +#...#.#...#.........#...#...#.#...#...#.....#...#...#...#...#...#.....#.#.#.....#.......#...#.....#...#.........#.#.....#.....#.#.#.#...#...# +#####.#.###.###.#.#.###.###.#.#.#.#.###.#############.###.#.#.###.#####.#.#.###.#######.###########.#####.#.###.#######.#.###.#.#.#.###.###.# +#.....#.#.......#.#...#.#...#.#.#...#...#.#.......#...#...#.#.#.#.........#...#.......#.........#.....#...#.#...#.....#.....#.#.#...#.....#.# +#.#####.#.#.#.###.###.#.#.###.#.###.#.###.#.#.###.#.###.###.#.#.#####.#######.#######.###.#####.###.#.#.###.#.#.#.###.###.#.#.#.###.#.#.#.#.# +#.#.....#.#...#.#...#...#...#.#.#.#.#.......#.#...#...#.#...#...#...#.......#.#.....#.........#.#.....#.....#.#...#.#.......#.#...#.#.#...#.# +#.###.#.#.#####.###.###.###.###.#.#.#.#####.#.#.###.#.#.#.#.###.#.#########.#.#.#.#.#########.#.#.###########.#####.#########.#.###.#.###.#.# +#...#.#.#.#.#.....#.#...#...#...#.#.#.....#.#.....#.#...#.#...#.#.#.......#...#.#.#.........#.#.#.......#.....#.............#...#...#.#.#.#.# +#.#.#.#.#.#.#.###.#.#.###.###.###.#.#####.###.###.#.#####.###.#.#.#.###.#.#####.#.#######.#.#.#.#.#####.#.#########.###########.#.#.#.#.#.#.# +#.#.#.#...#...#...#.#...#.#...#.#...#...#.....#.....#...#...#.#.#.#.#...#.#...........#.#.#.#...#...#.#.#.#.......#.............#.#...#...#.# +#.#.#.#####.###.#.#.###.#.#.###.#.###.#.#######.###.###.###.###.#.#.#.#####.#########.#.#.#.#####.#.#.#.#.#.#####.###########.#.#.#.#####.#.# +#.............#.#.#.#...#...#...#.#...#.#.....#.#.#...#...#.....#.#.#.......#.......#...#.............#...#...#.#.........#...#.#.#.....#.#.# +#.#.#.#.#.#####.#.#.###.#####.###.#.###.###.###.#.###.###.#######.#.#########.#####.#################.#######.#.#########.#.###.#.#.###.#.#.# +#.#.#.#.#.....#...#.................#.....#.#...#.....#.........#...#.....#...#.............#.....#...........#.....#...#.#.#.....#...#.#.#.# +###.#.#.#####.###.#########.#####.#######.#.#.###.#####.#######.###.#.#.###.###############.#.#.#.#.###########.#.###.#.#.#.#.#.###.#.#.#.#.# +#...#...#...#.........#...#.#.....#.....#...#.#.#.....#.......#...#...#.#...#.....#.......#...#...#...#...#.....#.....#.....#.#.....#.#.#.#.# +#.#######.#######.#####.#.###.###.#.###.#####.#.###.#.###.#.#.###.#####.#.#.#.###.#.#.#########.#####.#.#.###.#####.#######.#.#.#.#.#.#.#.#.# +#.....#.#.......#.#.....#.#...#.#.#.#.#.....#.#.#...#.#...#.#...#...#.#.#.....#...#.#.........#...#...#.#...#.#...#.......#.#.#.#.....#.#.#.# +#.###.#.#.#####.#.#.#####.#.###.#.#.#.#####.#.#.#.#.#.#.#.#####.###.#.#.#######.###.#######.#####.#####.###.#.#.#.#######.#.#.#.###.###.###.# +#.#.#.#.#...#.#...#...#.#.#.#...#...#...#...#...#.#...#.#.#...#.....#...#...#...#...#...#...#...#.....#...#.#.#.#.#.....#...#.....#...#...#.# +#.#.#.#.###.#.#######.#.#.#.#.#.#######.#.###.#.#.#.###.###.#.#####.#.#####.#.###.#####.#.###.#.#####.###.#.###.#.#.###.###.###.#.#.#####.#.# +#...#.#.#...#.......#...#...#.#.........#.....#.....#...#...#.....#.#.......#.#.#.....#.#.....#.....#.#...#.....#.#.#...#...#...#.#.#.....#.# +###.#.#.#.###.#.###.###.#############.#############.###.#.#######.#.#########.#.#####.#.###########.#.#.#########.#.#.###.#.#.#.#.###.#####.# +#...#.#...#.#.....#.#...#.#.........#.............#...#...#...#...#...........#.........#...#.....#.#...#...#...#...#.....#.#.#.#...#.......# +#####.#.###.#.###.###.###.#.#.#####.#######.#####.###.#####.#.#.###.###########.#######.###.#.###.#.#####.#.#.###########.#.#.#.###.#.####### +#.....#...#.....#...#.#.#...#.#...#...#.....#.#...#.#.#.....#.#...#.....#.......#...#.#...#.#.#.#.#.......#...#.........#.#.#.#.#...#...#...# +#.#######.#########.#.#.#.###.#.#.###.#.#####.#.###.#.#.#####.###.###.###.#####.#.#.#.###.#.#.#.#.#.###.#######.###.#####.#.###.#.#####.#.#.# +#...#...#...........#.#.#...#...#.......#.....#.#...#...#...#...#...#.#...#...#.#...#.....#.#.#.#.#...#.#...#...#...#.....#.....#.#.#...#.#.# +#.#.#.#.#.#.#########.#.###.###.#########.###.#.#.#######.#.###.###.#.#.###.#.###.#.###.###.#.#.#.###.###.#.#.###.#.#.#########.#.#.#.###.#.# +#.#...#.#.#.........#.#...#...#...#.....#...#.#.#.........#...#.#...#...#...#.....#...#...#.....#...#.#...#.....#.#.#.#.....#.#.#.....#.....# +#.#####.#.#######.#.#.###.###.###.#.###.###.###.#######.#####.#.#.#######.#.#########.###.#####.#.#.#.#.#########.#.#.#.###.#.#.#.#####.###.# +#.....#.#.......#.#.#...#...#...#.....#...#...#.#.......#.....#...#.....#.#.........#...#.....#.#.#.#.....#.......#.#...#...#...#.......#...# +#.#####.#######.#.#.###.###.###.#########.#.#.#.#.#####.#####.#####.###.#.#.###.#######.#.#.#.###.#.#####.#.#######.#####.#######.#######.#.# +#.#.....#.....#.#.#...#...#.....#.........#.#...#.#...#.#...#.#.....#.#...#.#.#.......#.#.........#...#.....#...#...#.#...#.....#.#...#...#.# +###.#######.###.#.###.###.#.#####.#########.#.###.###.#.#.#.#.#.#####.#####.#.#####.#.#.#############.#.#.###.#.#.###.#.###.###.#.#.#.#.###.# +#...............#.#...#...#.....#.#.#.......#.......#...#.#.#.#.#...#.....#.#.....#.#.#...#.........#.#.#.....#.#.#...#...#.#.#.#...#...#...# +#.###.#.#.###.###.#.###.#####.#.#.#.#.#######.#.###.#####.#.#.#.#.#.#.###.#.#.###.#.#####.#.#######.###.#.#.###.#.#.#.###.#.#.#.#####.####### +#.....#.#.....#...#...#.....#.#...#.#.....#...#.#...#.....#.#...#.#.#.#...#.#...#.#.....#.#...#.....#...#.#...#.#.#.#...#...#.#.....#.......# +#.#####.#.###########.#####.#.#####.#####.###.#.#.###.#####.#####.#.#.#.#.#.#.###.###.###.###.#####.#.###.###.###.#.#.#######.#####.#.#####.# +#.#.#...#.........#.....#...#.#.............#.#.#...#.#...#.#.....#...#.#.#.#.#.....#.............#...#.#.#.#...#.#.#.....#.......#.#.......# +#.#.#.#.#########.#.#####.###.#.#.#####.###.#.#.###.#.#.#.#.###########.#.#.###.###.#########.#.#.#####.#.#.###.#.#.###.#.###.#####.#.#####.# +#...#...#...#...#...#.....#...#.#.....#...#.#...#.#.#.#.#.#.......#.....#...#...#.....#.....#.#.#.#...........#...#...#.#...#.....#...#.#...# +#######.#.#.#.#.###.#.#####.#.#######.#.#.#.#.###.#.#.#.#########.#.###.#.###.###.#####.###.###.#.#.#############.#####.###.#.###.###.#.#.### +#.......#.#...#.....#.#...#.#.#.....#.#.#...#.....#.....#.........#.#.#.#.#...#...#.....#.#.....#.#.#.......#...#.......#.#.#...#.#.....#.#.# +#.#####.#.###.#######.#.#.###.#.###.#.#.#.###.###########.#.#######.#.#.#.#.#.#.###.#####.#######.###.#####.#.#.#######.#.#.###.#.#.#.###.#.# +#...................#...#.....#.#.....#.#.#.............#...........#...#.....#...#.............#...#.....#.#.#...#.....#.#.#...#.#.#.#...#.# +#.#.###.###.###.###.#########.#.###.#.###.#####.#######.#.#.#.###.#########.#####.#######.#.#.#.###.#####.#.#.###.###.#.#.#.#.###.#.#.#.###.# +#.....#.#...#...#.#.#.......#.#...#...#...#...#...#...#.#...#...#...........#.....#.#.....#.#.#.#.....#...#.....#.#...#...#.....#...#.#.#...# +#.###.#.#.###.###.#.#.###.#.#.#.#.#.###.###.#.###.#.#.#.###.###########.#.#.#.#####.#.#.###.#.#.#.###.#.#########.#.#########.#.#####.#.#.### +#.#.#.#.....#.....#.............#...#...#...#.....#.#...#...#.........#.#...#.#...#...................#.#.....#...#...........#.#...#.#.#...# +#.#.#.#.#####.#.#.#.###.#.#.#.#.###.#.###.###.#.#####.###.#.#.#######.###.#.#.#.#.#.#.#######.#####.#.#.#####.#.#########.#.#.#.#.#.#.#.#.#.# +#...#.#.....#...#.#.#...............#.#...#...#.#...#.#...#.#.....#.#...#.#.#.#.#.#.#.....#.....#...#...................#.#.#.#.#.#.#.#.#.#.# +###.#.#.###.#####.#.#.###.#.#.###.#.#.#.#.#.#.#.#.#.#.#.###.#####.#.###.#.#.#.#.#.#.#####.#####.#.###########.###.#.###.#.#.#.#.#.#.#.#.###.# +#.#.#...#.....#...#.....#.#.#...#.#...#.#...#.#.#.#.#...#.#...#.............#.............#.....#...#.......#...#.#.#...#.#.......#...#...#.# +#.#.#####.###.#.#########.#.#.#.#.#.#######.#.###.#.#####.#.#.#.###.#.#####.#######.#.#####.#######.#.#.###.###.#.#.#.#.#####.#####.#.###.#.# +#.#...#.......#.....#.#.....#.#.#.#.......#.......#.......................#.........#.#.....#...#...#.#.#.....#.#.#.#.#.#.......#...#.....#.# +#.###.#.###.#######.#.#.#####.#.#.#.#.###.#.#########.#####.#.#.#.#.#####.#.#########.#.#.###.#.#.###.#.###.#.#.#.#.#.###.###.#.#####.#####.# +#.........#.#.....#...#...............#...#.........#.#...#...#.#.#...#.#.....#.....#.#.#.#...#...#...#...#...#.#.#.#...#.....#...#...#.....# +#.#####.#.###.#.#####.###.#.###.###.###.###########.#.#.#.#####.###.#.#.#.#.#.#.###.#.#.#.#.#######.#####.#.###.#.#.#.#.#####.###.#.#######.# +#S......#.....#.........#.....#.........#...........#...#...........#...#...#.....#.....#.#.............#.......#.....#.........#...........# +############################################################################################################################################# \ No newline at end of file diff --git a/2024/day-16/maze.ts b/2024/day-16/maze.ts new file mode 100644 index 0000000..8358d11 --- /dev/null +++ b/2024/day-16/maze.ts @@ -0,0 +1,52 @@ +import { PriorityQueue } from "@datastructures-js/priority-queue" + +type Point = [number, number] +type OhGod = [number, number, number, number, number] +export function solveMaze(maze: string[][]): number { + const rows = maze.length + const cols = maze[0].length + let start: Point | null = null + + for (let r = 0; r < rows; r++) { + for (let c = 0; c < cols; c++) { + const char = maze[r][c] + if (char === "S") { + start = [r, c] + break + } + } + if (start) { + break + } + } + if (!start) throw Error("fuck") + const queue = new PriorityQueue((a, b) => a[0] - b[0]) + + queue.enqueue([0, start[0], start[1], 0, 1]) + + const seen = new Set([stringify(start[0], start[1], 0, 1)]) + + while (!queue.isEmpty()) { + const [cost, r, c, dr, dc] = queue.dequeue() + seen.add(stringify(r, c, dr, dc)) + if (maze[r][c] === "E") { + return cost + } + const options: OhGod[] = [ + [cost + 1, r + dr, c + dc, dr, dc], + [cost + 1000, r, c, dc, -dr], + [cost + 1000, r, c, -dc, dr], + ] + for (const [ncost, nr, nc, ndr, ndc] of options) { + if (maze[nr][nc] === "#" || seen.has(stringify(nr, nc, ndr, ndc))) { + continue + } + queue.enqueue([ncost, nr, nc, ndr, ndc]) + } + } + throw Error("shit") +} + +function stringify(v1: number, v2: number, v3: number, v4: number) { + return `${v1},${v2},${v3},${v4}` +} diff --git a/2024/day-16/test-input.txt b/2024/day-16/test-input.txt new file mode 100644 index 0000000..54f4cd7 --- /dev/null +++ b/2024/day-16/test-input.txt @@ -0,0 +1,17 @@ +################# +#...#...#...#..E# +#.#.#.#.#.#.#.#.# +#.#.#.#...#...#.# +#.#.#.#.###.#.#.# +#...#.#.#.....#.# +#.#.#.#.#.#####.# +#.#...#.#.#.....# +#.#.#####.#.###.# +#.#.#.......#...# +#.#.###.#####.### +#.#.#...#.....#.# +#.#.#.#####.###.# +#.#.#.........#.# +#.#.#.#########.# +#S#.............# +################# \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index 2ead000..11e26e6 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 1493061..be57428 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "typescript": "^5.0.0" }, "dependencies": { + "@datastructures-js/priority-queue": "^6.3.1", "remeda": "^2.17.4" } }