diff --git a/progress.png b/progress.png index 765b3a5..53ad9b7 100644 Binary files a/progress.png and b/progress.png differ diff --git a/progress.yaml b/progress.yaml index c090e10..336943a 100644 --- a/progress.yaml +++ b/progress.yaml @@ -25,4 +25,6 @@ 13: stars: 2 14: - stars: 2 \ No newline at end of file + stars: 2 +15: + stars: 1 \ No newline at end of file diff --git a/res/examples/day15_1.txt b/res/examples/day15_1.txt new file mode 100644 index 0000000..c6138ff --- /dev/null +++ b/res/examples/day15_1.txt @@ -0,0 +1,10 @@ +######## +#..O.O.# +##@.O..# +#...O..# +#.#.O..# +#...O..# +#......# +######## + +<^^>>>vv>v<< \ No newline at end of file diff --git a/res/examples/day15_2.txt b/res/examples/day15_2.txt new file mode 100644 index 0000000..b2bce78 --- /dev/null +++ b/res/examples/day15_2.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/src/day15/puzzle1.typ b/src/day15/puzzle1.typ new file mode 100644 index 0000000..bd80a00 --- /dev/null +++ b/src/day15/puzzle1.typ @@ -0,0 +1,91 @@ +#import "/src/utils.typ": * + +#let WALL = "#" +#let BOX = "O" +#let BOT = "@" +#let EMPTY = "." + +#let offsets = ( + "^": (0, -1), + "<": (-1, 0), + "v": (0, 1), + ">": (1, 0) +) + +#let compute-value(grid) = { + let total = 0 + for (y, row) in grid.enumerate() { + for (x, type) in row.enumerate() { + if type == BOX { + total += y * 100 + x + } + } + } + return total +} + +#let solve(input) = { + let (grid-data, move-data) = input.split("\n\n") + let grid = grid-data.split("\n").map(r => r.clusters()) + let rows = () + let cols = () + + let w = grid.first().len() + let h = grid.len() + let bot-pos = none + + for y in range(h) { + for x in range(w) { + let type = grid.at(y).at(x) + if type == BOT { + bot-pos = (x, y) + grid.at(y).at(x) = EMPTY + break + } + } + if bot-pos != none { + break + } + } + let (bot-x, bot-y) = bot-pos + + let moves = move-data.replace("\n", "").clusters() + for (move-i, move) in moves.enumerate() { + let (dx, dy) = offsets.at(move) + let (x2, y2) = (bot-x + dx, bot-y + dy) + let type = grid.at(y2).at(x2) + if type == WALL { + continue + } + if type == EMPTY { + (bot-x, bot-y) = (x2, y2) + continue + } + + let type2 = type + let (x3, y3) = (x2, y2) + while type2 == BOX { + x3 += dx + y3 += dy + type2 = grid.at(y3).at(x3) + } + + if type2 == WALL { + continue + } + grid.at(y3).at(x3) = BOX + grid.at(y2).at(x2) = EMPTY + (bot-x, bot-y) = (x2, y2) + } + + return compute-value(grid) +} + +#show-puzzle( + 15, 1, + solve, + example: ( + "1": 2028, + "2": 10092 + ) +) \ No newline at end of file diff --git a/src/day15/puzzle2.typ b/src/day15/puzzle2.typ new file mode 100644 index 0000000..e69de29 diff --git a/src/main.pdf b/src/main.pdf index 357390c..d0b54d2 100644 Binary files a/src/main.pdf and b/src/main.pdf differ