From 91f6052388dd78420cf83d34e060e4e98b6bfa47 Mon Sep 17 00:00:00 2001 From: pareronia <49491686+pareronia@users.noreply.github.com> Date: Sat, 16 Dec 2023 09:38:24 +0100 Subject: [PATCH] AoC 2023 Day 16 Part 2 --- README.md | 2 +- src/main/python/AoC2023_16.py | 50 ++++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6873e348..e7c70c4f 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | | ---| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | -| python3 | [✓](src/main/python/AoC2023_01.py) | [✓](src/main/python/AoC2023_02.py) | [✓](src/main/python/AoC2023_03.py) | [✓](src/main/python/AoC2023_04.py) | [✓](src/main/python/AoC2023_05.py) | [✓](src/main/python/AoC2023_06.py) | [✓](src/main/python/AoC2023_07.py) | [✓](src/main/python/AoC2023_08.py) | [✓](src/main/python/AoC2023_09.py) | [✓](src/main/python/AoC2023_10.py) | [✓](src/main/python/AoC2023_11.py) | [✓](src/main/python/AoC2023_12.py) | [✓](src/main/python/AoC2023_13.py) | [✓](src/main/python/AoC2023_14.py) | [✓](src/main/python/AoC2023_15.py) | | | | | | | | | | | +| python3 | [✓](src/main/python/AoC2023_01.py) | [✓](src/main/python/AoC2023_02.py) | [✓](src/main/python/AoC2023_03.py) | [✓](src/main/python/AoC2023_04.py) | [✓](src/main/python/AoC2023_05.py) | [✓](src/main/python/AoC2023_06.py) | [✓](src/main/python/AoC2023_07.py) | [✓](src/main/python/AoC2023_08.py) | [✓](src/main/python/AoC2023_09.py) | [✓](src/main/python/AoC2023_10.py) | [✓](src/main/python/AoC2023_11.py) | [✓](src/main/python/AoC2023_12.py) | [✓](src/main/python/AoC2023_13.py) | [✓](src/main/python/AoC2023_14.py) | [✓](src/main/python/AoC2023_15.py) | [✓](src/main/python/AoC2023_16.py) | | | | | | | | | | | java | [✓](src/main/java/AoC2023_01.java) | [✓](src/main/java/AoC2023_02.java) | [✓](src/main/java/AoC2023_03.java) | [✓](src/main/java/AoC2023_04.java) | [✓](src/main/java/AoC2023_05.java) | [✓](src/main/java/AoC2023_06.java) | [✓](src/main/java/AoC2023_07.java) | [✓](src/main/java/AoC2023_08.java) | [✓](src/main/java/AoC2023_09.java) | [✓](src/main/java/AoC2023_10.java) | [✓](src/main/java/AoC2023_11.java) | [✓](src/main/java/AoC2023_12.java) | [✓](src/main/java/AoC2023_13.java) | [✓](src/main/java/AoC2023_14.java) | [✓](src/main/java/AoC2023_15.java) | | | | | | | | | | | | rust | [✓](src/main/rust/AoC2023_01/src/main.rs) | [✓](src/main/rust/AoC2023_02/src/main.rs) | [✓](src/main/rust/AoC2023_03/src/main.rs) | [✓](src/main/rust/AoC2023_04/src/main.rs) | | [✓](src/main/rust/AoC2023_06/src/main.rs) | [✓](src/main/rust/AoC2023_07/src/main.rs) | [✓](src/main/rust/AoC2023_08/src/main.rs) | [✓](src/main/rust/AoC2023_09/src/main.rs) | | | | | | [✓](src/main/rust/AoC2023_15/src/main.rs) | | | | | | | | | | | diff --git a/src/main/python/AoC2023_16.py b/src/main/python/AoC2023_16.py index f6b69e59..a115e676 100644 --- a/src/main/python/AoC2023_16.py +++ b/src/main/python/AoC2023_16.py @@ -129,6 +129,7 @@ def get_energised( return ans def part_1(self, grid: Input) -> Output1: + sys.setrecursionlimit(10_000) log_grid(grid) energised = self.get_energised( grid, Cell(0, 0), Direction.RIGHT, set() @@ -136,13 +137,55 @@ def part_1(self, grid: Input) -> Output1: log(draw(energised, "#", ".")) return len(energised) - def part_2(self, input: Input) -> Output2: - return 0 + def part_2(self, grid: Input) -> Output2: + sys.setrecursionlimit(10_000) + ans = 0 + for row in range(grid.get_height()): + ans = max( + ans, + len( + self.get_energised( + grid, Cell(row, 0), Direction.RIGHT, set() + ) + ), + ) + ans = max( + ans, + len( + self.get_energised( + grid, + Cell(row, grid.get_width() - 1), + Direction.LEFT, + set(), + ) + ), + ) + for col in range(grid.get_width()): + ans = max( + ans, + len( + self.get_energised( + grid, Cell(0, col), Direction.DOWN, set() + ) + ), + ) + ans = max( + ans, + len( + self.get_energised( + grid, + Cell(grid.get_height() - 1, col), + Direction.UP, + set(), + ) + ), + ) + return ans @aoc_samples( ( ("part_1", TEST, 46), - # ("part_2", TEST, "TODO"), + ("part_2", TEST, 51), ) ) def samples(self) -> None: @@ -153,7 +196,6 @@ def samples(self) -> None: def main() -> None: - sys.setrecursionlimit(10_000) solution.run(sys.argv)