From 163455a42a8e480541ea3b1b6a8ec4017d09f1d3 Mon Sep 17 00:00:00 2001 From: Andres Date: Mon, 16 Dec 2024 22:09:01 +0100 Subject: [PATCH] 2024 day 16 part 1 --- 2024/day-16/day16.test.ts | 40 +++++++++++ 2024/day-16/day16.ts | 15 ++++ 2024/day-16/input.txt | 141 +++++++++++++++++++++++++++++++++++++ 2024/day-16/maze.ts | 52 ++++++++++++++ 2024/day-16/test-input.txt | 17 +++++ bun.lockb | Bin 7316 -> 8102 bytes package.json | 1 + 7 files changed, 266 insertions(+) create mode 100644 2024/day-16/day16.test.ts create mode 100644 2024/day-16/day16.ts create mode 100644 2024/day-16/input.txt create mode 100644 2024/day-16/maze.ts create mode 100644 2024/day-16/test-input.txt 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 2ead000cbdf0a13c744177057c255990fa51527e..11e26e6a76818a9c4227e51f8468c7d33db253f8 100755 GIT binary patch delta 1773 zcmcIke@xp|5P$Dm3Ts3jG2>p_od$uqeTDll6#-K z@7=q*?|b*|aKTB>K{4aBcriwmTs_hI(RjQ1p&^g4@C#LK_f&e#(8+Z-=63G3q%et0 zhkPkr_n8(H#{A8-4(EDjZd;%!Q0Hf?0}X1%y3-I-5sjR&L_{m<8pJT_WS>QhMRW;_ zX%T;jd`BOqM}1Ji*mA_@5t9&`5N(JRh*moaMI<1mBT@nbq6P6baK745Zyx;gyHcKN zzS3Kqwf}n!tl{VRW|-j~{tRRY9>W>T<3smoMBK^X1YZN+a#egL7P1))Q4xaz2Kj2T z2u&Os1-CH7;gsO!zr&2+5sC%KRJetG0yH9=6X2A>t$ZH?J_2tk?o}pYlnP0D9Hnwe zI*ZbSlB8A2(k_%9kiNZvQkf*p$&#=w8g42JyHIDuSRkXai3mxLAq9z$bQLn5EFHO| z<55dQNOnAO$w$7&|A1XmfTbMC`2QBTLCVjTDqzX)qXjW5xwo^ouIkOMzWYn3i?^E# z>nD%@mN61lp&zKf^~9=@v01%bBU8vlngScLz%XrH_4G&#G_iP!D(a^}KfZtEt`EW3%~J zy-$TRRwiZJ5A=7$&E#AkxE6jLPoA^+xOqe+l&gGDsn)@ms*J|~SNlMv(Lq36#?>&Q z_HhlUH9j5-eq6P18dn{}$NIP)8gPw+30w_e)B1QkwBniomvA*gs_qwf8=Kjn*9z|l zqsjVpQP8cc(ey-4=(q_UPH-=qzq>$msz&6=h}mR@;RNRvYJX}H9WuU07Kdy=jz>;F zrY+QL)PQvF)NuH&rH1pGQ9wFKq0*|zmHLp}=&4cvQEyTT+D_Xj6onw9@RWwqQCdn* zWl%ZPzvm<2ClldCV|g^s77N5&m@zJQ$wNne{Q{+tNFGm>d#Aowfxt5(Mcsz8CR?67xQ4#8xF&wxF&(w=L+B%q zwz#>Y{VDD%Cl)P53ecLZc4-*mteVan-E{7gTh)sWO$zXut!{aGjt>N^TMsv0Sagu* zYek=T-|)8UD;6zQ8r4XZR_Hfx!V`qg&CX?RyeXQ~&*r->^A7!dPsB@~0%?|#d%Si2 zpuauX7OD+~+5+v4#`dh1wua`mhTvXDYbX$cmP9)|XX)JeFMfe6$6q%F9C>&T*PJvhYxE~bCl|I!HhB*Wk%2L%%1tI$-DU4FJBrT#;B}pYpS?WWnLVETQrJy9G zs-hCtu7YcEB^_uXjPWZ8+9YDg^f+XEE73%CEQ3T0nVpq{+2k7k19sr`SO6yf--K-J zm9YdizhGijolap|8-!-99y0hKRlylP1Ol&z52&djRTqLO)OvJ5s)dLyM0v=L4^bUl z!80Ca@zjG`AEE~6!!rTq@iaoQAw&~l(6BtjDPb%@qgjX!7|a`PPt+Q(D)@nD8h1=k zY4+hbudQzoOEnSsUDUyx1TIS&Oqq=;)(aiXnw>7zJyt~4JvB1x(2gWLkb0#H`&bP2 z7>7n`Bx^Fe!ra+)c9o$KIRP2xp6HQroY`(jjb}sfI2!i41;UoacrmgIK3nbHEX;zf+t=0n)`hJKPKi;9(MpKC zh+}is!pYy2k(i~11JNdU<<<4)j%r%wT+1;BdATFriLz&Jf7Zn;BOF|^3CZ%`;7Pbq z*gf3xBIYo|!MIJ}KUt*W5Wx!XZDk+`d5)7$90qz6Yg8%>k 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" } }