2024 day 16 part 1

This commit is contained in:
2024-12-16 22:09:01 +01:00
parent 1c3cb46e40
commit 163455a42a
7 changed files with 266 additions and 0 deletions

40
2024/day-16/day16.test.ts Normal file
View File

@@ -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")
})

15
2024/day-16/day16.ts Normal file
View File

@@ -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(""))
}

141
2024/day-16/input.txt Normal file
View File

@@ -0,0 +1,141 @@
#############################################################################################################################################
#.#.....#...#...........#...........#.....#.......#.......#.....#...............#.........#.....#...#.....#.......#........................E#
#.#.###.#.#.#.###.###.#.###.#.###.###.#.#.#.#.###.#####.#.#.###.###.###.#####.###.#####.#.#.#.#.###.#.#.#.###.###.#.###.#.#.###.#######.###.#
#.....................#.....#.#...#...#.#.#.#...#...#...#.#...#...#.#.......#.....#...#.#.#.#.#...#...#.#...#...#.#...#.#.#.#...#.....#.....#
#.#.#.#########.#.#.###########.#.#.###.#.#.###.###.#.###.###.###.#.###.#.#.#########.#.#.#.#.###.#.###.###.###.#.###.#.#.#.#.#.#.#.#.#.#####
#.#.#.......#...#...#...................#.#...#...#...#.#.....#.#.#...#.#.#.....#.....#.#.#.#...#.#...#...#.....#.#...#...#...#...#.#.#...#.#
#.#.#.#####.#.###.#.#.#.#.#.#.###.#####.###.#####.#####.#######.#.###.#.#.#####.###.#.#.###.###.#.#####.#.#######.#.###########.###.#####.#.#
#.#.#...#...#.#...#.#.#...#.#...#.#.....#.........................#...#.#...#.#.....#.#.....#...#...............#.#.#...#.......#...#.....#.#
#.#.###.#####.#.#.#.#.#####.###.#.#.#####.#.#.#####.###.#########.#.###.###.#.###.###########.#.#######.###.#.#.#.#.#.#.#.#.###.#.#.#.#####.#
#.#.....#.....#.#.#.#.#...#...#...#.........#.#...#...#...........#...#...#.#.#...#...........#.........................#.#.#.#...#.#.......#
#.#.###.#.#####.###.#.#.#.#.#.#.#.#########.#.###.###.#########.#####.#####.#.#.###.###########.###.#.#.#####.#####.###.###.#.#.###.#######.#
#.............#.....#.#.#.#.#.#.#.....#...#...#.....#.#.......#.....#.....#.#...#.#...#...#...#...#...#.....#.#.......#.....................#
#.#.#####.#.#.#######.#.###.#.#.#.###.#.#.#.###.#####.#.#####.#.#########.#.#.###.###.#.###.#.#.#.###.#.#.#.#.###########.#.#.#.#.#.#.###.###
#...#...#...#.#.........#...#.....#...#.#...#.......#.#...#.#.#.......#.#...#.#.....#.#.#...#...#.#...#.#.#.#.#.......#...#.#...#.....#...#.#
#.#.#.#.###.#.#.#########.#####.#.#.###.#.#.#######.#.#.#.#.#.#.###.#.#.#.###.#####.#.#.#.#####.#.#.###.#.#.#.#.#####.#.###.###.#.#####.###.#
#.#...#.....#.#...#.....#...#.......#.....#...#.....#.#...#...#...#.#.....#.........#.#...#.......#.#...#.#.#...#...#.#...#.....#.#.........#
#.#.#######.#.###.#.#.#.###.#.###.###.#####.#.#.###.#.###.#.#######.#####.#.###.#####.#.###.#######.#####.#.#####.#.#.###.#.###.###.#.#.#.#.#
#.#...#.....#...#...#.#...#.....#...#.......#.#...#.#.....#.......#.#...#.#...#.#.....#.#...#.....#.......#.#.....#.#.....#...#.#...#.#.#.#.#
#.#.###.###.#.#.#.#.#.###.#####.#.#.#########.#.#.###############.#.#.#.#####.#.#.#####.#.###.###.#########.#####.#.#########.#.#.###.#.#.#.#
#.....#...#...#.....#...#...#.#.#.#...........#.#...#.....#.......#...#.....#...#.#...#.#.#.....#.........#.....#.#.#.....#...#...#.#...#.#.#
#.###.###.#.#.#.###.###.###.#.#.#.###.#.#######.###.#.#.#.#.#.#.###.#####.#.###.#.#.###.#.#.#######.#.#.#######.#.#.#.###.#.#######.#######.#
#...#.....#.#.#.#.......#.#.#...#...#.#.#.........#...#.....#.#.#.......#.#...#.#.#.#...#...#.....#...#.........#.#.#...#.#.#.....#.......#.#
#.#.#####.#.#.#.#.#####.#.#.#.###.#.###.#.###########.#.###.#.#.#.#####.#.#.#.#.#.#.#.#####.#.###.#.#.#######.#.#.###.###.#.###.#.#.#####.#.#
#.#...#...#.#.#.#.#.......#.#.#...#.#...#.#.....#...#.#.#.....#.........#.#.#...#.#.#.#.....#.#.#...#.........#...#...#...#.....#...#...#...#
#.#.###.###.#.###.#.#.#.###.#.#####.#.###.#####.#.#.###.#.#####.#.#####.#.#.#####.#.#.#.#.###.#.#####.###.#####.###.###.#############.#.#.#.#
#.#.#...#...#.....#.#.#.#...#.#.....#.#.....#...#.#.....#.....#...#...#.#...#...#.#.#.#.#.#...#.....#...#.....#.#...#.#.......#.....#.#...#.#
#.###.###.###.#####.#.###.###.#.###.#.#####.#.###.#####.#########.#.###.#####.#.#.#.#.###.#.###.###.#.#.###.#.#.#.###.#####.###.#.###.#.#.#.#
#.......#.....#.....#...#.#...#...#.#...#.....#...#.....#...#.....#.........#.#...#.#.....#.#...#.#...#.#...#...#.........#.....#.....#.#.#.#
#.#.###.#####.#.#.###.#.#.#.#.###.#####.#.#####.###.#####.#.#.###########.###.#####.###.###.#.###.#####.#.#.#############.#############.#.#.#
#...#...#...#.#.#...#.#...#.....#...#...#.#.#...#...#.....#...#.......#.....#.#.#.......#...#.........#.....#...........#.#...#.......#.....#
#.###.#.#.#.#.#.###.#.###.#####.###.#.###.#.#.###.###.#############.#.#.#.#.#.#.#.#####.#.###########.#####.#.#######.#.#.#.#.#######.###.###
#.#...#.#...#...#...#.........#.....#...#...#.#.....#...#.....#.....#.#...#.#.....#.....#.........#...#...#.#.#.#.....#.#...#.......#.......#
#.#.#.#.#.###.#.#.###########.#####.###.#####.#.#######.#.###.#.#####.#.#.#.#.###.#.###.###.#####.#.###.#.###.#.#.#####.###########.#.#.#.###
#.#.#.#...#...#.#.....#...#.....#.....#...#...#.#...#...#...#...#.#...#.#.#.#...#.#.#.#.......#.#.#.#...#.......#.#.#...#...#.....#.#.#.....#
#.###.#.###.#.#######.###.#.#.#.#.#######.#.###.#.#.#.###.#.###.#.#.###.#.#.#.#.###.#.###.###.#.#.###.###########.#.#.#.#.#.#.#.###.#.###.#.#
#...#.#.#...#.......#...#.#.#...#.#.......#...#.#.#.#.....#.....#.......#.#...#.#...#.#...#.#...#.....#.#.....#...#.#.#...#.#.#.#...#.#...#.#
###.#.###.#########.###.#.#.#.#.#.#.#######.#.###.#.#####.#.###.###.###.#.#.#.#.#.###.#.###.###.#######.#.#.###.###.#.###.#.#.#.#.###.###.#.#
#.#...#...#...#.....#...#...#.#.#.#.#...#...#.....#.....#.#...#...#...#.#.#.#.#...#...#.#...#.#...#...#...#.#...#.....#...#.#.#.#...#.....#.#
#.###.#.#####.#.#####.###.###.#.#.#.#.#.#.###########.#.#.#######.###.#.#.#.#.#####.#.#.#.#.#.###.#.###.###.#.###.#####.###.#.#####.#####.#.#
#.....#.#.....#.#.....#...#...#...#.#.#.#...#.......#.#...#...#...#.#.#.#.#...#...#.#.#.#.#...#...#.......#.#.#.#.......#.................#.#
#.#####.#.#.#.#.###.###.#.#.#######.#.#.###.#.#####.#####.#.#.#.###.#.###.#.#.#.#.#.#.#.#.#####.#####.#####.#.#.#.#########.###.#####.###.#.#
#.#.....#.#.#.#.....#.#...#.#...#...#.#.#...#...#...#...#...#.....#.......#.#.#.#.#.#.#.#...#...#...#.#...#.#.#...#...........#.#.......#...#
#.#.#.#####.#.#.#####.#.###.#.#.#.###.#.#.#####.#.###.#.#####.###.#########.#.#.#.###.#.#.#.#.###.#.#.#.#.#.#.#####.#########.#.#########.###
#.#.#.#...#.#.#.......#.#...#.#.#.....#.#.#.#...#.....#...#.#...#...#.......#...#.#...#.#.#.......#.#.#.....#.#.....#.......#.#.....#...#...#
#.#.###.#.#.###.#####.#.#.###.#.#######.#.#.#.#.#########.#.###.#.#.###.#########.#.#.#.#####.#####.###.#####.#.###########.#.#.###.#.#.#.#.#
#.#.#...#.#.....#...#...#...#.#.#...#...#...#.#.#...#.#...#...#.#.#...#.#.......#...#.#.#...#.#...#.#...#...#...#.........#.#.....#...#...#.#
#.#.#.###.#.#####.#########.#.#.#.#.#.#.###.#.###.#.#.#.#####.#.#####.#.#.#.###.#####.#.#.#.###.#.#.#.###.#.###.#.#.#####.#.###.#.#######.#.#
#...#.#...#...#.......#.....#.#.#.#...#.#...#.....#.#...#.....#.......#.#.#...#.......#...#.....#.#.#.#...#...#.#.#.#.....#...#...#.....#.#.#
#.###.#.#.###.#####.###.#####.#.#.#####.#.#.#######.#.###.#.###########.#.###.#######.#.#########.#.#.#.#####.#.###.#.#######.#.#.###.#.#.#.#
#...#.#.....#.#...#...#.#.....#.#.......#.#.........#.#...#.#.......#...#.#.#...#.....#.......#...#...#.#...#.#.....#.........#.#.....#.#.#.#
#.#.#.#####.#.#.#.###.#.#.#####.#####.#.#.###########.###.###.#.#.#.#.###.#.###.#####.###.#####.#.#####.#.#.#.#########.#.#.###.#.#######.#.#
#.#.#.#...#.#.#.#...#...#.....#...#.#.#.#...#.......#...#.........#.#.#.#.....#.....#...#.#...#.#.#.......#.#...#.....#.#.#...#...........#.#
###.#.#.#.#.#.#.###.#.#######.###.#.#.#####.#.#####.###.#######.#.###.#.#####.#####.###.#.#.#.#.#.#.#.#####.###.#.###.#.#####.#.#########.#.#
#...#.#.........#...#.........#.....#.....#.#.#...#...#.......#.#.....#...........#...#.#.#.#.#.#.#.#...#.#.#...#...#.#...#...#.............#
#.###.#.#.#.#####.#####.###########.#####.#.###.#.#.#########.###.#.#.###########.###.#.###.#.#.###.#.#.#.#.#.#####.#.###.#.###.#.#######.#.#
#.......#.#...#...#.....#...#...#.#.#...#.#.....#.#.#.........#.....#.......#...#.#.#.#.#...#...#...#.#.#...#.#.....#...#.#.#...#.#.....#.#.#
#####.#.###.#.#.###.#.#.#.#.#.#.#.#.###.#.#####.#.#.#.#####.###.###.#######.#.#.#.#.#.#.#.#####.#.###.#.#####.#.#.#######.#.#.#.#.#.###.#.#.#
#...#.#...#.#.#.#...#.#.#.#.#.#.#...#...#.#...#...#.#.#.....#...#.#...#.....#.#.#.#.#.#.#.....#.#...#.#.#.....#.#.........#...#.#.#.#.#.#.#.#
#.#.###.#.###.#.###.#.###.#.#.#.#.###.#.#.#.#.#.###.#.###.#.###.#.###.#####.#.###.#.#.#.###.#.###.###.#.#.#####.#.#########.###.#.#.#.#.#.#.#
#.#.....#...#.#.....#.....#.#.#.#.....#.#.....#...#.......#.#...#...#.....#.#.......#.#.....#.#...#...#...#...#.#.........#.....#...#.#.#...#
#.#########.#.#############.#.#.#############.###.#.#######.#.###.#.#####.#.#######.#.#.###.#.#.###.#######.#.#.#.#######.#####.###.#.#.#.###
#...#.....#...#.....#.......#.#.#.............#.#.#.#...#.....#...#.....#.#.....#...#.#.#...#...#...#.......#.#.#.#...#...#.........#.#.#.#.#
###.#.###.#####.###.#.#.#####.#.#.###########.#.#.###.#.###########.###.#.#####.#####.#.#.###.###.###.###.#####.#.#.#.#.#######.###.#.#.#.#.#
#...#.#.....#.....#.#.........#.#...#.#.....#...#...#.#.#.........#.#...#...#.........#.#.#...#...#.#.#.#.......#.#...........#...#.#.#.#...#
#.###.#.###.#.###.#############.#.#.#.#.###.###.###.#.#.#.#######.#.#######.###########.#.###.#.###.#.#.#########.#.#########.###.#.#.#.#.#.#
#...#.#...#.#.#.#.#...........#.#.#.#.#.#...........#.#...#.....#.#.......#...#...#.....#...#.#.#...#...#.........#.....#...#...#.#...#.#.#.#
#.#.#####.###.#.#.#.###.#####.#.###.#.#.#.###.#.#.###.#####.###.#.#####.#.###.###.#.###.###.#.#.###.###.#.#.#######.###.#.#.###.#.#.#.#.#.#.#
#.#.....#...#...#...#.#...#...#.....#.#.#.#...#.#.....#...#...#.#.....#.#...#.#...#...#...#.#.#...#.#...#.#...#...#...#...#...#.#.....#.#...#
#.#####.#.#.###.#####.#.#.#.#########.#.#.#####.#######.#.#.###.#####.###.#.#.#.#####.###.#.#.###.#.#.#######.#.#####.#######.#.###.#.#.#.###
#.....#.#.#.....#.....#...#.......#.....#.........#.....#...#...#...#...#.#.#.#...#...#...#.#...#.#.#.#.......#.#.....#.....#.#.....#.#.....#
#####.#.#.#######.###.#.###########.#############.#.#######.#.#.#.#.###.#.###.#.#.#.###.###.#####.#.#.#.###.###.#.#####.#.###.#.###.#######.#
#.#...#.#.....#.....#.#...........#.#...#.....#...#...#.....#.#.#.#...#.#.....#.#...#.#.....#.....#.#.#...#...#...#.....#.#.......#.....#...#
#.#.###.#####.#######.###########.#.#.#.#.###.#.#####.#.###.#.###.###.###.#####.#####.#######.#####.#.###.#.#.#.#####.#.#.#.###.###.###.#.###
#...#...#.#...#.........#.........#.#.#.#.#.#.#.#.....#...#.#...#.........#.#...#.......#.....#.....#.#...#.#...#...#...#.#.........#...#...#
#####.###.#.###.#######.#.#######.#.#.###.#.#.#.#.#.###.#.#.###.###.#.###.#.#.###.#######.#.###.###.#.#.#####.#.#.#.#####.#####.###.#.#####.#
#...#.#...#.....#...#...#...#.....#.#...#...#.#.#.....#.#.#.#.#...#.#.#...#.#...#.........#.#.....#.#.#.#...#.....#...#...........#.#.....#.#
#.#.#.#.#.#.#####.#.#.#####.#######.###.###.#.#######.#.#.#.#.###.#.#.#.###.###.###########.#.###.###.#.#.#.#########.#.#######.###.#####.#.#
#.#...#.#.#.....#.#.#.#...#.......#...#...#.#.#.......#...#.#...#...#...#...#.#.............#.#...#...#...#.....#...#.#.....#.....#.....#.#.#
#.#####.#.#.#.###.#.#.###.#######.###.###.#.#.#.#######.###.#.###########.#.#.#################.###.#####.#####.#.###.#####.#.#.#.#.#.#.#.#.#
#.#...#.#.#.#.....#.#.....#.....#.........#.#.#.#.......#.....#.........#.#.....#.........#.........#...#.....#.#...#.......#...#.#.#.#.#.#.#
#.#.#.###.#.#######.#####.###.#.###########.#.#.#.#####.#######.#####.#.#.#######.#######.#.#.###.###.#.#######.#.#.###.#######.#.#.#.###.#.#
#...#.#...#.........#...#...#.#...#...#.....#...#...#...#...#...#.....#.#.#.....#.......#...#.....#...#.........#.#.....#.....#.#.#.#...#...#
#####.#.###.###.#.#.###.###.#.#.#.#.###.#############.###.#.#.###.#####.#.#.###.#######.###########.#####.#.###.#######.#.###.#.#.#.###.###.#
#.....#.#.......#.#...#.#...#.#.#...#...#.#.......#...#...#.#.#.#.........#...#.......#.........#.....#...#.#...#.....#.....#.#.#...#.....#.#
#.#####.#.#.#.###.###.#.#.###.#.###.#.###.#.#.###.#.###.###.#.#.#####.#######.#######.###.#####.###.#.#.###.#.#.#.###.###.#.#.#.###.#.#.#.#.#
#.#.....#.#...#.#...#...#...#.#.#.#.#.......#.#...#...#.#...#...#...#.......#.#.....#.........#.#.....#.....#.#...#.#.......#.#...#.#.#...#.#
#.###.#.#.#####.###.###.###.###.#.#.#.#####.#.#.###.#.#.#.#.###.#.#########.#.#.#.#.#########.#.#.###########.#####.#########.#.###.#.###.#.#
#...#.#.#.#.#.....#.#...#...#...#.#.#.....#.#.....#.#...#.#...#.#.#.......#...#.#.#.........#.#.#.......#.....#.............#...#...#.#.#.#.#
#.#.#.#.#.#.#.###.#.#.###.###.###.#.#####.###.###.#.#####.###.#.#.#.###.#.#####.#.#######.#.#.#.#.#####.#.#########.###########.#.#.#.#.#.#.#
#.#.#.#...#...#...#.#...#.#...#.#...#...#.....#.....#...#...#.#.#.#.#...#.#...........#.#.#.#...#...#.#.#.#.......#.............#.#...#...#.#
#.#.#.#####.###.#.#.###.#.#.###.#.###.#.#######.###.###.###.###.#.#.#.#####.#########.#.#.#.#####.#.#.#.#.#.#####.###########.#.#.#.#####.#.#
#.............#.#.#.#...#...#...#.#...#.#.....#.#.#...#...#.....#.#.#.......#.......#...#.............#...#...#.#.........#...#.#.#.....#.#.#
#.#.#.#.#.#####.#.#.###.#####.###.#.###.###.###.#.###.###.#######.#.#########.#####.#################.#######.#.#########.#.###.#.#.###.#.#.#
#.#.#.#.#.....#...#.................#.....#.#...#.....#.........#...#.....#...#.............#.....#...........#.....#...#.#.#.....#...#.#.#.#
###.#.#.#####.###.#########.#####.#######.#.#.###.#####.#######.###.#.#.###.###############.#.#.#.#.###########.#.###.#.#.#.#.#.###.#.#.#.#.#
#...#...#...#.........#...#.#.....#.....#...#.#.#.....#.......#...#...#.#...#.....#.......#...#...#...#...#.....#.....#.....#.#.....#.#.#.#.#
#.#######.#######.#####.#.###.###.#.###.#####.#.###.#.###.#.#.###.#####.#.#.#.###.#.#.#########.#####.#.#.###.#####.#######.#.#.#.#.#.#.#.#.#
#.....#.#.......#.#.....#.#...#.#.#.#.#.....#.#.#...#.#...#.#...#...#.#.#.....#...#.#.........#...#...#.#...#.#...#.......#.#.#.#.....#.#.#.#
#.###.#.#.#####.#.#.#####.#.###.#.#.#.#####.#.#.#.#.#.#.#.#####.###.#.#.#######.###.#######.#####.#####.###.#.#.#.#######.#.#.#.###.###.###.#
#.#.#.#.#...#.#...#...#.#.#.#...#...#...#...#...#.#...#.#.#...#.....#...#...#...#...#...#...#...#.....#...#.#.#.#.#.....#...#.....#...#...#.#
#.#.#.#.###.#.#######.#.#.#.#.#.#######.#.###.#.#.#.###.###.#.#####.#.#####.#.###.#####.#.###.#.#####.###.#.###.#.#.###.###.###.#.#.#####.#.#
#...#.#.#...#.......#...#...#.#.........#.....#.....#...#...#.....#.#.......#.#.#.....#.#.....#.....#.#...#.....#.#.#...#...#...#.#.#.....#.#
###.#.#.#.###.#.###.###.#############.#############.###.#.#######.#.#########.#.#####.#.###########.#.#.#########.#.#.###.#.#.#.#.###.#####.#
#...#.#...#.#.....#.#...#.#.........#.............#...#...#...#...#...........#.........#...#.....#.#...#...#...#...#.....#.#.#.#...#.......#
#####.#.###.#.###.###.###.#.#.#####.#######.#####.###.#####.#.#.###.###########.#######.###.#.###.#.#####.#.#.###########.#.#.#.###.#.#######
#.....#...#.....#...#.#.#...#.#...#...#.....#.#...#.#.#.....#.#...#.....#.......#...#.#...#.#.#.#.#.......#...#.........#.#.#.#.#...#...#...#
#.#######.#########.#.#.#.###.#.#.###.#.#####.#.###.#.#.#####.###.###.###.#####.#.#.#.###.#.#.#.#.#.###.#######.###.#####.#.###.#.#####.#.#.#
#...#...#...........#.#.#...#...#.......#.....#.#...#...#...#...#...#.#...#...#.#...#.....#.#.#.#.#...#.#...#...#...#.....#.....#.#.#...#.#.#
#.#.#.#.#.#.#########.#.###.###.#########.###.#.#.#######.#.###.###.#.#.###.#.###.#.###.###.#.#.#.###.###.#.#.###.#.#.#########.#.#.#.###.#.#
#.#...#.#.#.........#.#...#...#...#.....#...#.#.#.........#...#.#...#...#...#.....#...#...#.....#...#.#...#.....#.#.#.#.....#.#.#.....#.....#
#.#####.#.#######.#.#.###.###.###.#.###.###.###.#######.#####.#.#.#######.#.#########.###.#####.#.#.#.#.#########.#.#.#.###.#.#.#.#####.###.#
#.....#.#.......#.#.#...#...#...#.....#...#...#.#.......#.....#...#.....#.#.........#...#.....#.#.#.#.....#.......#.#...#...#...#.......#...#
#.#####.#######.#.#.###.###.###.#########.#.#.#.#.#####.#####.#####.###.#.#.###.#######.#.#.#.###.#.#####.#.#######.#####.#######.#######.#.#
#.#.....#.....#.#.#...#...#.....#.........#.#...#.#...#.#...#.#.....#.#...#.#.#.......#.#.........#...#.....#...#...#.#...#.....#.#...#...#.#
###.#######.###.#.###.###.#.#####.#########.#.###.###.#.#.#.#.#.#####.#####.#.#####.#.#.#############.#.#.###.#.#.###.#.###.###.#.#.#.#.###.#
#...............#.#...#...#.....#.#.#.......#.......#...#.#.#.#.#...#.....#.#.....#.#.#...#.........#.#.#.....#.#.#...#...#.#.#.#...#...#...#
#.###.#.#.###.###.#.###.#####.#.#.#.#.#######.#.###.#####.#.#.#.#.#.#.###.#.#.###.#.#####.#.#######.###.#.#.###.#.#.#.###.#.#.#.#####.#######
#.....#.#.....#...#...#.....#.#...#.#.....#...#.#...#.....#.#...#.#.#.#...#.#...#.#.....#.#...#.....#...#.#...#.#.#.#...#...#.#.....#.......#
#.#####.#.###########.#####.#.#####.#####.###.#.#.###.#####.#####.#.#.#.#.#.#.###.###.###.###.#####.#.###.###.###.#.#.#######.#####.#.#####.#
#.#.#...#.........#.....#...#.#.............#.#.#...#.#...#.#.....#...#.#.#.#.#.....#.............#...#.#.#.#...#.#.#.....#.......#.#.......#
#.#.#.#.#########.#.#####.###.#.#.#####.###.#.#.###.#.#.#.#.###########.#.#.###.###.#########.#.#.#####.#.#.###.#.#.###.#.###.#####.#.#####.#
#...#...#...#...#...#.....#...#.#.....#...#.#...#.#.#.#.#.#.......#.....#...#...#.....#.....#.#.#.#...........#...#...#.#...#.....#...#.#...#
#######.#.#.#.#.###.#.#####.#.#######.#.#.#.#.###.#.#.#.#########.#.###.#.###.###.#####.###.###.#.#.#############.#####.###.#.###.###.#.#.###
#.......#.#...#.....#.#...#.#.#.....#.#.#...#.....#.....#.........#.#.#.#.#...#...#.....#.#.....#.#.#.......#...#.......#.#.#...#.#.....#.#.#
#.#####.#.###.#######.#.#.###.#.###.#.#.#.###.###########.#.#######.#.#.#.#.#.#.###.#####.#######.###.#####.#.#.#######.#.#.###.#.#.#.###.#.#
#...................#...#.....#.#.....#.#.#.............#...........#...#.....#...#.............#...#.....#.#.#...#.....#.#.#...#.#.#.#...#.#
#.#.###.###.###.###.#########.#.###.#.###.#####.#######.#.#.#.###.#########.#####.#######.#.#.#.###.#####.#.#.###.###.#.#.#.#.###.#.#.#.###.#
#.....#.#...#...#.#.#.......#.#...#...#...#...#...#...#.#...#...#...........#.....#.#.....#.#.#.#.....#...#.....#.#...#...#.....#...#.#.#...#
#.###.#.#.###.###.#.#.###.#.#.#.#.#.###.###.#.###.#.#.#.###.###########.#.#.#.#####.#.#.###.#.#.#.###.#.#########.#.#########.#.#####.#.#.###
#.#.#.#.....#.....#.............#...#...#...#.....#.#...#...#.........#.#...#.#...#...................#.#.....#...#...........#.#...#.#.#...#
#.#.#.#.#####.#.#.#.###.#.#.#.#.###.#.###.###.#.#####.###.#.#.#######.###.#.#.#.#.#.#.#######.#####.#.#.#####.#.#########.#.#.#.#.#.#.#.#.#.#
#...#.#.....#...#.#.#...............#.#...#...#.#...#.#...#.#.....#.#...#.#.#.#.#.#.#.....#.....#...#...................#.#.#.#.#.#.#.#.#.#.#
###.#.#.###.#####.#.#.###.#.#.###.#.#.#.#.#.#.#.#.#.#.#.###.#####.#.###.#.#.#.#.#.#.#####.#####.#.###########.###.#.###.#.#.#.#.#.#.#.#.###.#
#.#.#...#.....#...#.....#.#.#...#.#...#.#...#.#.#.#.#...#.#...#.............#.............#.....#...#.......#...#.#.#...#.#.......#...#...#.#
#.#.#####.###.#.#########.#.#.#.#.#.#######.#.###.#.#####.#.#.#.###.#.#####.#######.#.#####.#######.#.#.###.###.#.#.#.#.#####.#####.#.###.#.#
#.#...#.......#.....#.#.....#.#.#.#.......#.......#.......................#.........#.#.....#...#...#.#.#.....#.#.#.#.#.#.......#...#.....#.#
#.###.#.###.#######.#.#.#####.#.#.#.#.###.#.#########.#####.#.#.#.#.#####.#.#########.#.#.###.#.#.###.#.###.#.#.#.#.#.###.###.#.#####.#####.#
#.........#.#.....#...#...............#...#.........#.#...#...#.#.#...#.#.....#.....#.#.#.#...#...#...#...#...#.#.#.#...#.....#...#...#.....#
#.#####.#.###.#.#####.###.#.###.###.###.###########.#.#.#.#####.###.#.#.#.#.#.#.###.#.#.#.#.#######.#####.#.###.#.#.#.#.#####.###.#.#######.#
#S......#.....#.........#.....#.........#...........#...#...........#...#...#.....#.....#.#.............#.......#.....#.........#...........#
#############################################################################################################################################

52
2024/day-16/maze.ts Normal file
View File

@@ -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<OhGod>((a, b) => a[0] - b[0])
queue.enqueue([0, start[0], start[1], 0, 1])
const seen = new Set<string>([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}`
}

View File

@@ -0,0 +1,17 @@
#################
#...#...#...#..E#
#.#.#.#.#.#.#.#.#
#.#.#.#...#...#.#
#.#.#.#.###.#.#.#
#...#.#.#.....#.#
#.#.#.#.#.#####.#
#.#...#.#.#.....#
#.#.#####.#.###.#
#.#.#.......#...#
#.#.###.#####.###
#.#.#...#.....#.#
#.#.#.#####.###.#
#.#.#.........#.#
#.#.#.#########.#
#S#.............#
#################