diff --git a/day_15/example_1.txt b/day_15/example_1.txt new file mode 100644 index 0000000..b2bce78 --- /dev/null +++ b/day_15/example_1.txt @@ -0,0 +1,21 @@ +########## +#..O..O.O# +#......O.# +#.OO..O.O# +#..O@..O.# +#O#..O...# +#O..O..O.# +#.OO.O.OO# +#....O...# +########## + +^v>^vv^v>v<>v^v<<><>>v^v^>^<<<><^ +vvv<<^>^v^^><<>>><>^<<><^vv^^<>vvv<>><^^v>^>vv<>v<<<^<^^>>>^<>vv>v^v^<>><>>>><^^>vv>v<^^^>>v^v^<^^>v^^>v^<^v>v<>>v^v^v^^<^^vv< +<>^^^^>>>v^<>vvv^>^^^vv^^>v<^^^^v<>^>vvvv><>>v^<<^^^^^ +^><^><>>><>^^<<^^v>>><^^>v>>>^v><>^v><<<>vvvv>^<><<>^>< +^>><>^v<><^vvv<^^<><^v<<<><<<^^<^>>^<<<^>>^v^>>^v>vv>^<<^v<>><<><<>v<^vv<<<>^^v^>^^>>><<^v>>v^v><^^>>^<>vv^ +<><^^>^^^<>^vv<<^><<><<><<<^^<<<^<<>><<><^^^>^^<>^>v<> +^^>vv<^v^v^<>^^^>>>^^vvv^>vvv<>>>^<^>>>>>^<<^v>^vvv<>^<>< +v^^>>><<^^<>>^v^v^<<>^<^v^v><^<<<><<^vv>>v>v^<<^ \ No newline at end of file diff --git a/day_15/example_2.txt b/day_15/example_2.txt new file mode 100644 index 0000000..c6138ff --- /dev/null +++ b/day_15/example_2.txt @@ -0,0 +1,10 @@ +######## +#..O.O.# +##@.O..# +#...O..# +#.#.O..# +#...O..# +#......# +######## + +<^^>>>vv>v<< \ No newline at end of file diff --git a/day_15/example_3.txt b/day_15/example_3.txt new file mode 100644 index 0000000..dfe6a69 --- /dev/null +++ b/day_15/example_3.txt @@ -0,0 +1,9 @@ +####### +#...#.# +#.....# +#..OO@# +#..O..# +#.....# +####### + +vv<>^vv>>>^v>^>><>^<^v<>v>>><^><^v<>^v><<<><<>vv>^v^v<^vvv>>vv^>^vv^^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^^^><<>>>v><v<^<>^>^v>v>v^^^^^>>v>vvv<^>v<^v>v>v>^<^<^>v<><^v>v>v>>v<<>>^<<<^>v><>>><^>v<<><>^><>><>v>^v>^<^v<<><^<^v>vv>>>v>^^>v>v>^^><<^vv><<<<^^><^^<>vv^vv^^<<^^^^vv><><^vvv<><>^v><^<<<^<^>v>^v^<^<^<^vv>v^>>^<>>^^<^>>>^<^><^^^v<^^>^>v>v<>v<<<><^vvv^v<>>v<><^^<><><>^vv>>v^<^<^v^<^><<^<<>vvv>><>>vv><^v<vvv^^v^>^><>^>>^^v^<^v^v><<>v>^vv<^<^^^>>vv<^<v><^v>v^^v>^<^^v<^^>^vvv>^v<<^^^^<^^<^>vv>^v><^>>><>vv^<>^>v^>v<><><^v^^^><<>>^^^><^^v^<<>^>^<^>v>v<>^<>^^>>>>v^v>^>><<^vv<>^^^>>v>v>^^^>^<^^<^>v^<>^^<^>^^^^vv<><<<>><v<><>^<^vvv^>vv^^v<>v<>^<^<>><><^>>>v<<<>vv<>>>^^vvv>^<<<>^vvvv>>^<^><>^>>^vvv<>v><^^v>^^<<>><^v<>^v<<<>^^^>>>^>v<<<<^^><<>v^>>><>>^><^^><><^<^<<<<<>^>v>^<><>vvvv^><^^^>^>>><<>vv>v>>>^v<>vvv<<^>>>^v>>vv>^>^^>^>^vv<^^^>v<^>>>^^>>v<^v>v<vv>><>^v>>><^vv><<^^v>^>v>vv^^^<<>v^^>^<>>v^v>^>^>v^>^^><^^>^v^<vv>>^^v>>^>^vv<>><>^^>v>v>^v^<>>v><>>>>v>>v>><>vvv<^v<>><^ \ No newline at end of file diff --git a/day_15/solve_1.ts b/day_15/solve_1.ts new file mode 100644 index 0000000..2f722fd --- /dev/null +++ b/day_15/solve_1.ts @@ -0,0 +1,105 @@ +export type Map = string[][]; + +export type Move = "^" | "v" | "<" | ">"; + +export async function readData(path: string): Promise<{ + map: Map, + moves: Move[] +}> { + const text = await Deno.readTextFile(path); + const [ + map, + moves + ] = text.split("\n\n"); + return { + map: map.split("\n").map((line) => line.split("")), + moves: moves.split("\n").join("").split("").map((move) => move as Move) + }; +} + +export function displayMap(map: Map): string { + return map.map((line) => line.join("")).join("\n"); +} + +export function foreachMap(map: Map, callback: (value: string, x: number, y: number) => void): void { + map.forEach((line, y) => { + line.forEach((value, x) => { + callback(value, x, y); + }); + }); +} + +export const dirToDelta = { + "^": [0, -1], + "v": [0, 1], + "<": [-1, 0], + ">": [1, 0] +} + +export function stepRobot(map: Map, robot: {x: number, y: number}, move: Move): void { + const {x, y} = robot; + const [dx, dy] = dirToDelta[move]; + // Check if the robot can move + + // like socoban, @ is the robot, # is a wall, . is a free space, O is a box + // multiple boxes can be pushed at the same time + let nextX = x; + let nextY = y; + while (true) { + nextX += dx; + nextY += dy; + const nextValue = map[nextY][nextX]; + if (nextValue === "#") { + // The robot can't move + return; + } + else if (nextValue === ".") { + break; + } + if (nextValue === "O") { + continue; + } + } + let prevX = nextX; + let prevY = nextY; + // move the boxes + while (prevX !== x || prevY !== y) { + map[prevY][prevX] = map[prevY - dy][prevX - dx]; + prevX -= dx; + prevY -= dy; + } + // move the robot + map[y][x] = "."; + robot.x = x + dx; + robot.y = y + dy; +} + +if (import.meta.main) { + const {map, moves} = await readData("input.txt"); + let robot = { + x: 0, + y: 0 + } + foreachMap(map, (value, x, y) => { + if (value === "@") { + robot = { + x, + y + } + } + }); + console.log("Robot", robot); + console.log(displayMap(map)); + moves.forEach((move) => { + // console.log("Move", move, ":"); + stepRobot(map, robot, move); + // console.log(displayMap(map)); + }); + let sum = 0; + foreachMap(map, (value, x, y) => { + if (value === "O") { + sum += x + y * 100; + } + }); + console.log("Sum", sum); +} \ No newline at end of file diff --git a/day_15/solve_2.ts b/day_15/solve_2.ts new file mode 100644 index 0000000..45efe11 --- /dev/null +++ b/day_15/solve_2.ts @@ -0,0 +1,187 @@ +import { displayMap, foreachMap, Map, Move, readData } from "./solve_1.ts"; + +const extendingTranslation = { + "#": "##", + ".": "..", + "O": "[]", + "@": "@.", +}; + +function extendMap(map: Map) { + const extendedMap = map.map((row) => { + return row.map((value) => { + const v = extendingTranslation[ + value as keyof typeof extendingTranslation + ]; + if (v) { + return v; + } + throw new Error("Invalid value"); + }).join("").split(""); + }); + return extendedMap; +} + +function getHugeBoxPos(map: Map, boxPos: [number, number]): [number, number] { + const [x, y] = boxPos; + const anyBracket = map[y][x]; + if (anyBracket === "]") { + return [x - 1, y]; + } + if (anyBracket === "[") { + return [x, y]; + } + throw new Error("Not a huge box"); +} + +function IsMovableHugeBox( + map: Map, + boxPos: [number, number], + move: Move, +): boolean { + const [x, y] = getHugeBoxPos(map, boxPos); + if (move === "^" || move === "v") { + const dy = move === "^" ? -1 : 1; + if (map[y + dy][x] === "#" || map[y + dy][x + 1] === "#") { + return false; + } + if (map[y + dy][x] === "." && map[y + dy][x + 1] === ".") { + return true; + } + + if (map[y + dy][x] === "]") { + const success = IsMovableHugeBox(map, [x, y + dy], move); + if (!success) { + return false; + } + } else if (map[y + dy][x] === "[") { + const success = IsMovableHugeBox(map, [x, y + dy], move); + if (!success) { + return false; + } + } + if (map[y + dy][x + 1] === "[") { + const success = IsMovableHugeBox(map, [x + 1, y + dy], move); + if (!success) { + return false; + } + } + return true; + } else { + const dx = move === "<" ? -1 : 2; + const [nx, ny] = [x + dx, y]; + if (map[ny][nx] === "#") { + return false; + } + if (map[ny][nx] === ".") { + return true; + } + return IsMovableHugeBox(map, [nx, ny], move); + } +} + +function pushHugeBox(map: Map, boxPos: [number, number], move: Move) { + const [x, y] = getHugeBoxPos(map, boxPos); + if (move === "^" || move === "v") { + const dy = move === "^" ? -1 : 1; + if (map[y + dy][x] === "]") { + pushHugeBox(map, [x, y + dy], move); + } else if (map[y + dy][x] === "[") { + pushHugeBox(map, [x, y + dy], move); + } + if (map[y + dy][x + 1] === "[") { + pushHugeBox(map, [x + 1, y + dy], move); + } + if (map[y + dy][x] === "." && map[y + dy][x + 1] === ".") { + map[y][x] = "."; + map[y][x + 1] = "."; + map[y + dy][x] = "["; + map[y + dy][x + 1] = "]"; + return; + } else { + throw new Error("can't push the box"); + } + } else { + if (map[y][x - 1] === "]" && move === "<") { + pushHugeBox(map, [x - 1, y], move); + } + if (map[y][x + 2] === "[" && move === ">") { + pushHugeBox(map, [x + 2, y], move); + } + const dx = move === "<" ? -1 : 1; + const nx = x + dx; + if ( + (move === "<" && map[y][nx] === ".") || + (move === ">" && map[y][nx + 1] === ".") + ) { + map[y][x] = "."; + map[y][x + 1] = "."; + map[y][nx] = "["; + map[y][nx + 1] = "]"; + return; + } else { + throw new Error("can't push the box"); + } + } +} + +function stepRobot(map: Map, robot: { x: number; y: number }, move: Move) { + const { x, y } = robot; + const dx = move === "<" ? -1 : move === ">" ? 1 : 0; + const dy = move === "^" ? -1 : move === "v" ? 1 : 0; + const nx = x + dx; + const ny = y + dy; + if (map[ny][nx] === "#") { + return; + } + if (map[ny][nx] === "[" || map[ny][nx] === "]") { + const [hx, hy] = getHugeBoxPos(map, [nx, ny]); + if (IsMovableHugeBox(map, [hx, hy], move)) { + pushHugeBox(map, [hx, hy], move); + } else { + return; + } + } + map[y][x] = "."; + map[ny][nx] = "@"; + robot.x = nx; + robot.y = ny; +} + +if (import.meta.main) { + let { map, moves } = await readData("input.txt"); + console.log(displayMap(map)); + map = extendMap(map); + let robot = { + x: 0, + y: 0, + }; + foreachMap(map, (value, x, y) => { + if (value === "@") { + robot = { + x, + y, + }; + } + }); + console.log("Robot", robot); + console.log(displayMap(map)); + moves.forEach((move) => { + // console.log("Move", move, ":"); + try { + stepRobot(map, robot, move); + } catch (_e) { + console.log("Move", move, ":"); + console.log(displayMap(map)); + } + // console.log(displayMap(map)); + }); + let sum = 0; + foreachMap(map, (value, x, y) => { + if (value === "[") { + sum += x + y * 100; + } + }); + console.log(displayMap(map)); + console.log("Sum", sum); +}