From 566032d375e65abb17e417faf7f9c1f64de2eaba Mon Sep 17 00:00:00 2001 From: Botond Hende Date: Sun, 15 Dec 2024 18:48:54 +0100 Subject: 2024 day15 --- 2024/day15/input | 71 +++++++++++++++++++++++++++++ 2024/day15/input_test | 10 +++++ 2024/day15/input_test2 | 21 +++++++++ 2024/day15/solve.py | 67 ++++++++++++++++++++++++++++ 2024/day15/solve2.py | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 288 insertions(+) create mode 100644 2024/day15/input create mode 100644 2024/day15/input_test create mode 100644 2024/day15/input_test2 create mode 100644 2024/day15/solve.py create mode 100644 2024/day15/solve2.py diff --git a/2024/day15/input b/2024/day15/input new file mode 100644 index 0000000..a153680 --- /dev/null +++ b/2024/day15/input @@ -0,0 +1,71 @@ +################################################## +#.#.#......O....##.#O.##..O.........O........O.#.# +#......O..........O..O.O.....O.........#O.......O# +#.OO....#.O.O.OO#....#.OO.....O.##....O.......O.O# +#..........O...#O#.......#OO....O.O..O#........OO# +#O..O.....O..O..#.O.O...O..#.O.O.....O.#....OOO..# +#O#O..O..O.OO.#..O...........#.......#O.OO.O.O..## +#.O..OO.O.#.#.......O......O..........O.O..#.....# +#...O..O..O...OO....O....O....#.OO.#..O.....O..### +###.#.O..O.O.O..O.....O.O.#.....O.O......OO....#O# +#....O.....OO.O#..#..O.O...OO..................#O# +#....OO...O.O.OO.O#.O...O..#..O.#.#....O.O.O.OO.## +##.##....O#O.......O#..O.OOO....O.....O....O#..O.# +#...O..O....#O...O..O.OO..OOO.##O...........O.#O.# +#..O....O.#O...OO....OO.O..O.#OO..O....O.....O...# +#O#O..O.......OO...#.....O#OOO....#.O...O.......O# +#O.O.....OO#.#.O..........#..O#.....O..O#...O..### +#...#.....O#..O....##OO.O.#.#......O......OOO..O.# +#OO.O....O.OO..O.........OO.O.....#.O.O...O..O#O.# +#..O#..O#.OO.OOOO..O..O.......#O#..OO...OO.O....O# +#O.#O#....#..O.#..O#O.OO..O.O.#....#.OOO...O.....# +#.......#..OOOOO...O..OOO..O...O.OO....OO.OOOO...# +#...O..#..OO..OOO.O.#O.#..#.O..O...O#.....O.....O# +#.OOOO.....OOOOO...OO........O#....O.....O.#...#.# +#O#OO.#O..........O..OOO@.O.....O.....#O...O..OOO# +#.#............OO....O......O#O..#O..O.O.........# +#.O.O.....O....O.O.OO.O..O...#........OO.#O....O.# +#......OOOO......O#.#.O...#O.O.OO..O.O...O.O...OO# +#OO#.#O..O...#.O..O.....O...OO.O.....##.O.....O..# +#..#O.#OO.OOO..OOO.#..OO..#.O...OOO......#......## +#O.O#.O..O.......O..OO....#....O..O..O....O...#..# +#..OO.O...............##O..O..OO....O.OO...O...OO# +#.#O........O...O.O....#O#........O.....#..#O....# +#......#....O#......#.#.#...#........O..OOO..O..O# +#O.#OO.##..........O.#O.O.#O.#OO#....O..OO...OO..# +#...OO.......#...##..#......O.O.OO.OOOO.O.#.#....# +##.O..#..O#......OO.....#....O..#..O..O.#.OO..#..# +#....O.OOO.O..O#........O.O...OO...O...O.O....O..# +#OOOO.OO...O.O..#O.OO.O#......#OO..O.O.....O..O..# +#..#.O..O..#O......O...OO.......#O...#..#O#.O..O.# +#O...#..OOO.O#O.O.O.O.O..O...O.O#..O..O..O.#..OO.# +#.....O.O.O..O.O..OO.........#O.....O...O......O.# +#O...OOO....O.OO..#....O#O...O.O..O.O.......OOO.O# +#OO#..O##..O...O.#..O....##..OOO...O.O##.##..#.OO# +#OO.......O##.#..O.OO......O..O..O..O....O.O...O.# +#.....O...O.O.#..O..O.#..O.OOO#.......#.........## +#..O.O.OO....#...OOO.OO..O....O.#.O.O##....OOO...# +#OO#O..#.....O.....O.....O...O#O..O..O#......O#..# +#O....#.OOO.O#.OO..O...OOO.OOOO...OO#O.O.O.....OO# +################################################## + +<><>^<^^vv>^^v^vvvv<>>^<>v>v>^<^v<><<<>>>><>vv^^v<^><^^vv^v^><>vvvv^v><>^v>>><^vvv<>v<>^^^vvv<>v>>^v>>^^>>>>^<^^^>^>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^v^^v<<>>v>^^<<<<^^^^v>v>v^^>v>^^v^^^v>>vv<^^v>^^v^<>vvv^^>>v>^<^<^v>^<^>><^<<^><>v^v>v^<>><<<<^^<>>^>^>>v<>v<^>>v<<<<>>v^<^v>v>^^v<><<<^v^^<<<>^v^^vvv^v>>^^>v<>v^>>>v<<>^><><<>^vv>^v^^v^>v^^^vv<^<>vvv>^v>><<^>v>v^<^^vv>v<>^>>>>>>v<^>v<^^<>^vvv><^<>^>>>^ +><<<^v>v>^>^^>^>^^v>>^v>v>^^v<^<<>^^<>v><>vv>v^>^^>vv>^<<><^v^>vv<^v>^vv^<<^<<<^v^^<><^><<<<>>^><^>^vvv>>^vv>>v>><^^v^>^^<^<^<>^v>^v>^v><<>^>v^^vv^^^v^v^v<^vv^^vvv^^^v>^>>^>vvv>>^^<^>^v<>>^^>>v>^^<>v>>v<^^>v<^^v>^<>>^^v><>^^v^v^<^<<^^<<<>^v>v^<<^v>vv^^>>><<^^><^v>^vv<<^>>^>^vvv><>v<^v>vvv^^^>^^>^^>v^><^<^v<><<>^<^>v>v>><>^>><^<<>v^<<^v><^<^<>><^<<^v><^^>^^v<^>>^^v<<^<>v^v>v><<^<<^<>^>v>^^<^^vv<<>^v^<^>v^v>v<<^v>><><<><><<^<<>^>vvv<><<^<<^v><>v<>v>v>v><^>v^v<^^v^^<>vvv>^^<><><>^><^<>><^^^>>>^^>v>v><>v>^^v^<<^^<>>>^>>vv><^>v>^<>^v>v^<^>v^><<<^<<^><><^^v<^<<>v<>>>>v><^^vvvv^<^^^^><^^<^>>^v>v^^v^<^vv^>^<><>>^vvv<<^>v>v><^v^^<>^<^<<<>>>v>>^v^><>v^<>vvv<<>v>^v>^^v>^vv^<^^<^vv>v<^^v^^<^^>^vv^>v>vv<<>>v^^<^^^v^>v<>^^<>>vv>v<< \ No newline at end of file diff --git a/2024/day15/input_test2 b/2024/day15/input_test2 new file mode 100644 index 0000000..b2bce78 --- /dev/null +++ b/2024/day15/input_test2 @@ -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/2024/day15/solve.py b/2024/day15/solve.py new file mode 100644 index 0000000..5459df4 --- /dev/null +++ b/2024/day15/solve.py @@ -0,0 +1,67 @@ +def move(data: list[list[str]], current_pos: tuple[int, int], + current_order: str, movement_dict: dict[str, tuple[int, int]]) -> tuple[int, int]: + assert data[current_pos[0]][current_pos[1]] == "@" + + direction = movement_dict[current_order] + can_move = True + steps = 0 + while True: + steps += 1 + current_tile = data[current_pos[0] + direction[0] * steps][current_pos[1] + direction[1] * steps] + if current_tile == "#": + can_move = False + break + elif current_tile == ".": + break + + if can_move: + data[current_pos[0]][current_pos[1]] = "." + if steps > 1: + data[current_pos[0] + direction[0] * steps][current_pos[1] + direction[1] * steps] = "O" + current_pos = (current_pos[0] + direction[0], current_pos[1] + direction[1]) + data[current_pos[0]][current_pos[1]] = "@" + + return current_pos + +def calculate_gps_data(data: list[list[str]]): + result = 0 + for row_pos, row in enumerate(data): + for col_pos, char in enumerate(row): + if char == "O": + result += row_pos * 100 + col_pos + return result + +movement_dirs = { "<": (0, -1), "v": (1, 0), "^": (-1, 0), ">": (0, 1) } +map_data = [] +movement_data = "" + +with open("input") as f: + reading_movement = False + for line in f: + line = line.strip() + if reading_movement: + movement_data += line + else: + if line == "": + reading_movement = True + else: + map_data.append(list(line)) + +for row_idx, row in enumerate(map_data): + for col_idx, char in enumerate(row): + if char == "@": + robot_row = row_idx + robot_col = col_idx + break + else: + continue + break + +new_pos = (robot_row, robot_col) +for order in movement_data: + new_pos = move(map_data,new_pos, order, movement_dirs) + +for line in map_data: + print("".join(line)) + +print(calculate_gps_data(map_data)) \ No newline at end of file diff --git a/2024/day15/solve2.py b/2024/day15/solve2.py new file mode 100644 index 0000000..86e5c82 --- /dev/null +++ b/2024/day15/solve2.py @@ -0,0 +1,119 @@ +def get_affected_boxes_if_can_move(data: list[list[str]], current_pos: tuple[int, int], + affected_box_positions: list[tuple[int, int]], direction: tuple[int, int]) -> bool: + current_char = data[current_pos[0]][current_pos[1]] + if current_char == "]": + current_pos = (current_pos[0], current_pos[1] - 1) + + if current_char in affected_box_positions: + return True + + if current_char != "@": + affected_box_positions.append(current_pos) + + pushed_positions = [] + if current_char == "@": + pushed_positions.append(direction) + elif direction == (0, 1): + pushed_positions.append((0, 2)) + elif direction == (0, -1): + pushed_positions.append(direction) + else: + pushed_positions.append(direction) + pushed_positions.append((direction[0], 1)) + + for pushed in pushed_positions: + pushed_pos = (current_pos[0] + pushed[0], current_pos[1] + pushed[1]) + pushed_char = data[pushed_pos[0]][pushed_pos[1]] + if pushed_char == "#": + return False + elif pushed_char == "[" or pushed_char == "]": + success = get_affected_boxes_if_can_move(data, pushed_pos, affected_box_positions, direction) + if not success: + return False + + return True + + +def move(data: list[list[str]], current_pos: tuple[int, int], + current_order: str, movement_dict: dict[str, tuple[int, int]]) -> tuple[int, int]: + assert data[current_pos[0]][current_pos[1]] == "@" + + direction = movement_dict[current_order] + can_move = True + steps = 0 + affected_box_positions = [] + success = get_affected_boxes_if_can_move(data, current_pos, affected_box_positions, direction) + if not success: + return current_pos + + data[current_pos[0]][current_pos[1]] = "." + for box_pos in affected_box_positions: + data[box_pos[0]][box_pos[1]] = "." + data[box_pos[0]][box_pos[1] + 1] = "." + + current_pos = (current_pos[0] + direction[0], current_pos[1] + direction[1]) + data[current_pos[0]][current_pos[1]] = "@" + + for box_pos in affected_box_positions: + data[box_pos[0] + direction[0]][box_pos[1] + direction[1]] = "[" + data[box_pos[0] + direction[0]][box_pos[1] + direction[1] + 1] = "]" + + return current_pos + +def calculate_gps_data(data: list[list[str]]): + result = 0 + max_cols = len(data[0]) + for row_pos, row in enumerate(data): + for col_pos, char in enumerate(row): + if char == "[": + result += row_pos * 100 + col_pos + return result + +movement_dirs = { "<": (0, -1), "v": (1, 0), "^": (-1, 0), ">": (0, 1) } +map_data = [] +movement_data = "" + +with open("input") as f: + reading_movement = False + for line in f: + line = line.strip() + if reading_movement: + movement_data += line + else: + if line == "": + reading_movement = True + else: + new_line = [] + map_data.append(new_line) + for char in line: + if char == ".": + new_line.append(".") + new_line.append(".") + elif char == "#": + new_line.append("#") + new_line.append("#") + elif char == "O": + new_line.append("[") + new_line.append("]") + else: + new_line.append(char) + new_line.append(".") + +for row_idx, row in enumerate(map_data): + for col_idx, char in enumerate(row): + if char == "@": + robot_row = row_idx + robot_col = col_idx + break + else: + continue + break + +new_pos = (robot_row, robot_col) +for order in movement_data: + new_pos = move(map_data,new_pos, order, movement_dirs) + +for line in map_data: + print("".join(line)) + +print(calculate_gps_data(map_data)) \ No newline at end of file -- cgit v1.2.3-70-g09d2