diff --git a/README.md b/README.md index 071a529..b7b1a04 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ _My solutions to the 2024 edition of [Advent of Code](https://adventofcode.com/2 | **[12](https://adventofcode.com/2024/day/12)** | [solution](src/main/scala/adventofcode/solutions/Day12.scala) | | **[13](https://adventofcode.com/2024/day/13)** | [solution](src/main/scala/adventofcode/solutions/Day13.scala) | | **[14](https://adventofcode.com/2024/day/14)** | [solution](src/main/scala/adventofcode/solutions/Day14.scala) | -| **[15](https://adventofcode.com/2024/day/15)** | [](src/main/scala/adventofcode/solutions/Day15.scala) | +| **[15](https://adventofcode.com/2024/day/15)** | [solution](src/main/scala/adventofcode/solutions/Day15.scala) | | **[16](https://adventofcode.com/2024/day/16)** | [](src/main/scala/adventofcode/solutions/Day16.scala) | | **[17](https://adventofcode.com/2024/day/17)** | [](src/main/scala/adventofcode/solutions/Day17.scala) | | **[18](https://adventofcode.com/2024/day/18)** | [](src/main/scala/adventofcode/solutions/Day18.scala) | diff --git a/input/15.txt b/input/15.txt new file mode 100644 index 0000000..784de23 --- /dev/null +++ b/input/15.txt @@ -0,0 +1,71 @@ +################################################## +#O##.OO.O........OO.#...OO#.......O..O.....O....O# +#OO......O..OOO.O#...O....O#.O#.O##...........OO.# +#....OO##O.O....OO.OO.OO...OO#..O.O.O.#.....#.O#.# +#..#..O.O#..O...OO..O..O.....OOO#.O........O.O#O.# +#O.#.#OO..#.......O.O..OOOO.O.....O.O............# +#........OO...O.#.O..O.....O.O.O.O...O..O....OOOO# +#.#OO..O....#..#.....O....#.OO....#..#.OO..O.O...# +#....OOO....O.......#.#OO.......O......OO..O#O.#O# +#...##.O....O..O.O..#..OO.O...O...O..OO....O#...## +##OO.O....O....O..OO....O....O##O.O..O.....#.OO..# +#..O........O..O...#.OOO.OO...O..#OO....O....O...# +#..........OO..O..#O.............#O.O#.#.O....O.O# +#...O.OO.......OO.........O.OOO...O.OO...OO..OO.O# +#.O..O.OO..#.....................O...O......O..O.# +##OO#.O.#...O.....OO..O.........O#....OO...O#....# +#.O.#..O.OOOO.O...O.O.OOOO..O...#......#O.O..OO.O# +#...OO....OOOO.OO.#.#O..O..OO.........O.O.......O# +#...#...#.O#....O.#O....O.O.O......OO..OO......O.# +#.O#.#O..#O...OO..O......O..O..O.O...O..O...O...O# +#.......O........OOO....O..#O#.....O#............# +#.OOOO......#........#...O..O..#......O..O.O..#..# +#OOO...O...O..OO.O..O.#O.......O....O#..#.O..O...# +#..O...##.O.OO#..O..O..O.....O...................# +##O......OO.O...OO#.O.#.@...O...O...........#..O.# +#O.O..OO.O..O......O.OO......OOO.....#..OOO..O...# +#....O....O.O.......#.O..O....#..#...O..O..O.OO.O# +#.......OO..O.....O..O#.O...OOO.O.O...OO#..O..O..# +#..#.#O.....OO..O.O..O......O#.OOOO...O.O.OO.O#..# +#..O.....O.#O#.....#O..OOO.OO.O.......O.O.O.O....# +#OO#O..##......O.O...O#.OO.....O....O.....O.#..O.# +#..#O....O..O.O#.#..#O.#O.#....#..O...#.O..OO.O..# +#OO.....#O....O.#O..O.OO..O.##O.O..O..O.OO.O.##..# +#O.OO.............O...O..#....O.O.OO....#O.OO...O# +#.....O#......O.O.O..O...O#O..O.#..OO.....#..O.O.# +#.OO..O.O..O....O#...#..OO.O.##.....O..#O..O...O.# +#O..O..#.#..#.....O....O.....O.##.#.......O......# +#O....O.....O..#.#OO.OO.#...........#.#.#O.....O## +#...O.....O..#......O.O.O.OO..O#.O#...OOO.OO..#..# +#....O.O.#O....#.......O.......#....O...O..O.....# +#.......O#....O..OOO.#OO..#...OO#....OO.OOO.....O# +#....#O.O.#OO.OO..O..O...#O.##.#O...O.#...O.O..O.# +#O.O...OOO.OO.#O.....O.........#OO.O....#.O......# +#.O.O.......O....OO......O..O.O.....O...O........# +#O#..#O#......#.O.......OO...............O....O#.# +#..O.OO.....O.O.O#O.O.OO.OO.O.....#O##..#O.#...O## +#..OO#.O..#.O.O.#O..O...O.#.#O..O....O....#O..O..# +#.O...O#.OO.......#.O..O...#.#OO.#..O.O...OO#O.O.# +#.....OO#....O....O.O...O..OOO......O....O#.....O# +################################################## + +^^<>v^v^v>><<^<^<>>v>vv^<>^>^>><^>>>^<^v>^>v<^<<^>^<^v<^^vvv^<^^v^v>^<>vvv<<<^><<^v^^^vv^vv<><><^v<^>>v^vv<>>>>v>vv>v^>><>vv^^<<^^<><<<^v><<^v^vvv^vv^^vv^vv><<<>v<^^<^vv<^^>v^^>^><^^v<^^>v<^^^>>><<>>^^>vv<>^^v>v>v<^^<><<^>^^vv><<<^<<<>>v^^vv>^v>v><>^vv^^<><>^vvv^vv^>^^v^^>>v<>>>^>><><>v>v<<^v^vv^<^vv>v>v^v^>>^>^^>v^v^><><^<>v^<^^^v<>>^v^^v^<>v><^<^v^^vv<>^v^<>vvv<><>><^<^^<^^v>vv>>><<<^^v^v^>vv^>v^v<><>^>^>>><>^^v^^<>v^v>>v^<>v<^>^^v>^>v>v^vv<^>v>v>>^<><^^<^v^<^>^>>vv^<^v^>^^>^><>>^^<^^><<<<<^<^>>>^><>>v^^vv<>>^>><<<<>^>v^vvv^vv<^>^<<<<>>v<>^><^v^vv^v<><^>^v>v<^>vv^v><<^>>v^>v<^><<>>>v<<<<^<><>^<>v>^vv>^<>^^^vv<><^>v<<^><<^v<^v>^v>^>^v<>v<^>><<^<<<<<<^<>^^^<<>>v>v^v<^^v^^^vv^^<>v>v<><>vv<><^>><<><<><^>^v<^>v^<>>v^ +>^<>v<>^^^><^^^^^>^v<^>v^vvv<<<<^v^^<>^vv^<^>v>^^^v^v^<<<><^^v>^v<<>^v><^<>^>^v<<<^<>^<<>>v<^<^^^^v>>>>v^^<^v>vvvv>v<^vv<><<>^^vv<>^^^<^^v>v<<>><^^<<<<>^^v^^>><^^vv^>^v^^<>vv^vv^>^>v><^<<>>vv<>^<^^>v^v^^vvv^>v<<><^^v>>vv<>vv<^^v>^^>v^v^vvv>^^^^^v>^<<>^^>vv><<<>>vvv<^vvvv<>^<^<<<<^<^v<^v^^><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v>>vv^^^^^>vvv^vv<^^<^>vv><>v>^<^^^v^><^v><^vvv<^^vv^<>^<vv^v>v<<>>>>^>>^vvv>>^vv><^^><^>^^>>v>^v>v<<<>><^v^>>>^>^><vvv<> \ No newline at end of file diff --git a/output/15-1.txt b/output/15-1.txt new file mode 100644 index 0000000..8479b39 --- /dev/null +++ b/output/15-1.txt @@ -0,0 +1 @@ +1448589 \ No newline at end of file diff --git a/output/15-2.txt b/output/15-2.txt new file mode 100644 index 0000000..90e4edc --- /dev/null +++ b/output/15-2.txt @@ -0,0 +1 @@ +1472235 \ No newline at end of file diff --git a/src/main/scala/adventofcode/solutions/Day15.scala b/src/main/scala/adventofcode/solutions/Day15.scala new file mode 100644 index 0000000..a732760 --- /dev/null +++ b/src/main/scala/adventofcode/solutions/Day15.scala @@ -0,0 +1,82 @@ +package adventofcode.solutions + +import adventofcode.Definitions.* + +@main def Day15 = Day(15) { (input, part) => + + case class Vec(i: Int, j: Int): + infix def +(that: Vec): Vec = Vec(i + that.i, j + that.j) + infix def *(v: Int): Vec = Vec(i * v, j * v) + def gps: Int = i * 100 + j + def twice: Vec = Vec(i, j * 2) + def directions2: Seq[Vec] = Seq(this, this + Vec(0, 1)) + def collidingFromBox2: Seq[Vec] = if i != 0 then Seq(this + Vec(0, -1), this) else if j > 0 then Seq(this) else Seq(this * 2) + def collidingBoxes2: Seq[Vec] = if i != 0 then Seq(this, this + Vec(0, 1)) else if j > 0 then Seq(this * 2) else Seq(this) + + case class State(robot: Vec, boxes: Set[Vec]) + + val (((initialRobot, initialBoxes), grid), instructions) = + input.split(lineSeparator * 2).toSeq match + case Seq(first, second) => + val rawGrid = first.split(lineSeparator).map(_.toIndexedSeq).toIndexedSeq + def collectPositions(c: Char): Set[Vec] = + rawGrid.zipWithIndex.flatMap((row, i) => row.zipWithIndex.collect { case (`c`, j) => Vec(i, j) }).toSet + collectPositions('@').head -> collectPositions('O') -> rawGrid.map(_.map { + case '#' => false + case _ => true + }) -> second.split(lineSeparator).mkString.map { + case '^' => Vec(-1, 0) + case '>' => Vec(0, 1) + case 'v' => Vec(1, 0) + case '<' => Vec(0, -1) + } + + val initialState = State(initialRobot, initialBoxes) + + def walkable(p: Vec): Boolean = grid(p.i)(p.j) + + def move(state: State, direction: Vec): State = + val nextRobot = state.robot + direction + if walkable(nextRobot) then + val pushBoxes = LazyList.from(1).map(i => state.robot + direction * i).takeWhile(state.boxes.contains) + val canBePushed = pushBoxes.lastOption.forall(p => walkable(p + direction)) + if canBePushed then + State(nextRobot, state.boxes -- pushBoxes ++ pushBoxes.map(_ + direction)) + else + state + else + state + + val finalState = instructions.foldLeft(initialState)(move) + + part(1) = finalState.boxes.toSeq.map(_.gps).sum + + val initialState2 = State(initialRobot.twice, initialBoxes.map(_.twice)) + + def walkable2(p: Vec): Boolean = grid(p.i)(p.j / 2) + + def bfsBoxes(direction: Vec, positions: Set[Vec], accBoxes: Set[Vec], boxes: Set[Vec]): Set[Vec] = + val newBoxes = boxes.intersect(positions) + if newBoxes.nonEmpty then + val nextPositions = newBoxes.flatMap(_.directions2).flatMap(b => direction.collidingFromBox2.map(b + _)) + bfsBoxes(direction, nextPositions, accBoxes ++ newBoxes, boxes) + else + accBoxes + + def move2(state: State, direction: Vec): State = + val nextRobot = state.robot + direction + if walkable2(nextRobot) then + val pushBoxes = bfsBoxes(direction, direction.collidingFromBox2.map(state.robot + _).toSet, Set.empty, state.boxes) + val canBePushed = pushBoxes.flatMap(p => direction.collidingBoxes2.map(p + _)).forall(walkable2) + if canBePushed then + State(nextRobot, state.boxes -- pushBoxes ++ pushBoxes.map(_ + direction)) + else + state + else + state + + val finalState2 = instructions.foldLeft(initialState2)(move2) + + part(2) = finalState2.boxes.toSeq.map(_.gps).sum + +}