From a6415eb7ce6a507e3f75850eba70254ff8cae02a Mon Sep 17 00:00:00 2001 From: Florian Cassayre Date: Sat, 30 Dec 2023 22:18:05 +0100 Subject: [PATCH] Solved day 23 --- README.md | 2 +- input/23.txt | 141 ++++++++++++++++++ output/23-1.txt | 1 + output/23-2.txt | 1 + .../scala/adventofcode/solutions/Day23.scala | 93 ++++++++++++ 5 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 input/23.txt create mode 100644 output/23-1.txt create mode 100644 output/23-2.txt create mode 100644 src/main/scala/adventofcode/solutions/Day23.scala diff --git a/README.md b/README.md index d8550ab..c20529a 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ _My solutions to the 2023 edition of [Advent of Code](https://adventofcode.com/2 | **[20](https://adventofcode.com/2023/day/20)** | [solution](src/main/scala/adventofcode/solutions/Day20.scala) | | **[21](https://adventofcode.com/2023/day/21)** | [solution](src/main/scala/adventofcode/solutions/Day21.scala) | | **[22](https://adventofcode.com/2023/day/22)** | [solution](src/main/scala/adventofcode/solutions/Day22.scala) | -| **[23](https://adventofcode.com/2023/day/23)** | [](src/main/scala/adventofcode/solutions/Day23.scala) | +| **[23](https://adventofcode.com/2023/day/23)** | [solution](src/main/scala/adventofcode/solutions/Day23.scala) | | **[24](https://adventofcode.com/2023/day/24)** | [](src/main/scala/adventofcode/solutions/Day24.scala) | | **[25](https://adventofcode.com/2023/day/25)** | [](src/main/scala/adventofcode/solutions/Day25.scala) | diff --git a/input/23.txt b/input/23.txt new file mode 100644 index 0000000..1ea10b7 --- /dev/null +++ b/input/23.txt @@ -0,0 +1,141 @@ +#.########################################################################################################################################### +#.#...###...#.......#.....#.....###.....###...#...#.....###...#.............#.......#...#...#...#.....#...#####.....#...###.....#...#####...# +#.#.#.###.#.#.#####.#.###.#.###.###.###.###.#.#.#.#.###.###.#.#.###########.#.#####.#.#.#.#.#.#.#.###.#.#.#####.###.#.#.###.###.#.#.#####.#.# +#.#.#.....#...#.....#.#...#...#...#...#.###.#.#.#.#...#.###.#.#.....#.......#...#...#.#.#.#.#.#.#...#.#.#...###.#...#.#...#...#...#.###...#.# +#.#.###########.#####.#.#####.###.###.#.###.#.#.#.###.#.###.#.#####.#.#########.#.###.#.#.#.#.#.###.#.#.###.###.#.###.###.###.#####.###.###.# +#.#.#.......#...#...#.#.#...#.#...#...#...#.#...#...#.#...#.#.#####.#.#...>.>.#.#.###.#.#.#.#.#.###.#.#...#.....#...#.#...###.....#...#...#.# +#.#.#.#####.#.###.#.#.#.#.#.#.#.###.#####.#.#######.#.###.#.#.#####.#.#.###v#.#.#.###.#.#.#.#.#.###.#.###.#########.#.#.#########.###.###.#.# +#.#.#.....#...###.#...#...#.#.#...#.....#.#...#.....#.#...#.#.###...#.#.#...#...#...#.#...#.#.#.#...#.>.>.#.........#.#.###...###.#...###.#.# +#.#.#####.#######.#########.#.###.#####.#.###.#.#####.#.###.#.###.###.#.#.#########.#.#####.#.#.#.#####v###.#########.#.###.#.###.#.#####.#.# +#...#.....###...#.........#.#.#...#.....#.#...#.#...#.#...#.#.>.>.###...#.#...#...#.#...#...#.#.#.#####...#...###...#.#...#.#.#...#.#...#.#.# +#####.#######.#.#########.#.#.#.###.#####.#.###.#.#.#.###.#.###v#########.#.#.#.#.#.###.#.###.#.#.#######.###.###.#.#.###.#.#.#.###.#.#.#.#.# +#...#.#.....#.#.#...#...#.#.#.#.###.....#.#.#...#.#.#...#.#...#.###.....#.#.#.#.#.#...#.#.#...#.#...#...#...#...#.#.#.#...#.#.#...#.#.#.#.#.# +#.#.#.#.###.#.#.#.#.#.#.#.#.#.#.#######.#.#.#.###.#.###.#.###.#.###.###.#.#.#.#.#.###.#.#.#.###.###.#.#.###.###.#.#.#.#.###.#.###.#.#.#.#.#.# +#.#...#...#.#.#.#.#.#.#...#...#...>.>.#.#.#.#...#.#...#.#.#...#...#.#...#...#...#...#...#.#.###.#...#.#.#...###.#.#.#.#.#...#...#.#...#...#.# +#.#######.#.#.#.#.#.#.#############v#.#.#.#.###.#.###.#.#.#.#####.#.#.#############.#####.#.###.#.###.#.#.#####.#.#.#.#.#.#####.#.#########.# +#.#...#...#...#.#.#.#.#.......#.....#.#.#...###.#.###.#.#.#.#...#...#...#.......#...###...#...#.#.#...#.#.....#...#.#.#.#.....#.#.###.....#.# +#.#.#v#.#######.#.#.#.#.#####.#.#####.#.#######.#.###.#.#.#.#.#.#######.#.#####.#.#####.#####.#.#.#.###.#####.#####.#.#.#####.#.#.###.###.#.# +#...#.>.#...#...#.#...#...#...#.....#.#.......#.#...#...#...#.#.#...#...#.....#.#.....#...#...#...#...#.......#...#...#.......#.#.#...###...# +#####v###.#.#.###.#######.#.#######.#.#######.#.###.#########.#.#.#.#.#######.#.#####.###.#.#########.#########.#.#############.#.#.######### +#...#.....#.#...#.###...#.#.#...#...#...#.....#.#...###.......#.#.#.#...#####.#.#.....#...#.....#.....#.........#.........#...#...#.........# +#.#.#######.###.#.###.#.#.#.#.#.#.#####.#.#####.#.#####.#######.#.#.###.#####.#.#.#####.#######.#.#####.#################.#.#.#############.# +#.#.........###...#...#...#...#...#...#.#.....#.#.....#.......#...#.....#.....#...#...#.....#...#.......#.....#...........#.#.#.............# +#.#################.###############.#.#.#####.#.#####.#######.###########.#########.#.#####.#.###########.###.#.###########.#.#.############# +#.................#.#...#...#.......#.#.......#...#...#.......#.....#...#...........#.....#.#...#.......#...#.#.#...###...#.#.#.............# +#################.#.#.#.#.#.#.#######.###########.#.###.#######.###.#.#.#################.#.###.#.#####.###.#.#.#.#.###.#.#.#.#############.# +#...#.............#...#.#.#.#.#.......#...#.....#...###.........#...#.#.........#.....#...#.....#.#...#.....#...#.#...#.#.#.#.#.........#...# +#.#.#.#################.#.#.#.#.#######.#.#.###.#################.###.#########.#.###.#.#########.#.#.###########.###.#.#.#.#.#.#######.#.### +#.#.#...........#...###.#.#...#.......#.#...#...#.....#...###...#...#...#.....#...###...###.....#...#...#.....###...#.#.#.#.#.#.......#.#.### +#.#.###########.#.#.###.#.###########.#.#####.###.###.#.#.###.#.###.###.#.###.#############.###.#######.#.###.#####.#.#.#.#.#.#######v#.#.### +#.#.###.........#.#...#...#.........#...#.....###...#...#.....#.....###.#.###.....#...#...#.#...#.....#...#...#.....#.#.#.#.#...#...>.#.#...# +#.#.###.#########.###.#####.#######.#####.#########.###################.#.#######.#.#.#.#.#.#.###.###.#####.###.#####.#.#.#.###.#.###v#.###.# +#.#.....#...#.....#...#...#.......#.......#...###...#...#.............#...###.....#.#.#.#.#.#.#...#...###...###.....#.#.#...###...#...#.....# +#.#######.#.#.#####.###.#.#######.#########.#.###.###.#.#.###########.#######.#####.#.#.#.#.#.#.###.#####.#########.#.#.###########.######### +#.........#...#...#.#...#.#...###...#...#...#...#.....#...###.........#.......#...#.#...#.#.#.#...#.#...#...###.....#.#.#.....#.....###...### +###############.#.#.#.###.#.#.#####.#.#.#.#####.#############.#########.#######.#.#.#####.#.#.###.#.#.#.###v###.#####.#.#.###.#.#######.#.### +###...#...#.....#...#...#.#.#.......#.#.#.#.....#...#...#...#.....#...#.........#.#.#.....#.#...#.#.#.#...>.>.#.....#.#.#...#.#.........#...# +###.#.#.#.#.###########.#.#.#########.#.#.#.#####.#.#.#.#.#.#####.#.#.###########.#.#.#####.###.#.#.#.#####v#.#####.#.#.###.#.#############.# +#...#...#...###...#...#.#.#.#.....###.#.#.#.#...#.#.#.#.#.#...#...#.#...#.........#.#.#...#...#.#.#...###...#.#...#.#.#.###.#...............# +#.#############.#.#.#.#.#.#.#.###.###.#.#.#.#.#.#.#.#.#.#.###.#.###.###.#.#########.#.#.#.###.#.#.#######.###.#.#.#.#.#.###.################# +#...#...###.....#.#.#.#.#.#...#...#...#.#.#.#.#.#.#.#.#.#...#.#...#.#...#.....#...#.#.#.#.#...#.#.#.......###.#.#.#.#...#...#...#...........# +###.#.#v###.#####.#.#.#.#.#####.###.###.#.#.#.#.#.#.#.#.###.#.###v#.#.#######.#.#.#.#.#.#.#.###.#.#.#########.#.#.#.#####.###.#.#.#########.# +###...#.>.#...#...#.#.#.#.#...#...#...#.#.#.#.#.#.#.#.#...#.#...>.>.#...#...#.#.#.#.#...#.#.###...#.........#.#.#.#.....#...#.#.#.#.........# +#######v#.###.#.###.#.#.#.#.#.###v###.#.#.#.#.#.#.#.#.###.#.#####v#####.#.#.#v#.#.#.#####.#.###############.#.#.#.#####.###.#.#.#.#.######### +#.......#.....#.#...#...#.#.#.#.>.>...#.#.#.#.#.#.#.#...#.#.#.....#...#.#.#.>.>.#...#.....#...###...#.......#...#.#.....###...#.#.#.###.....# +#.#############.#.#######.#.#.#.#v#####.#.#.#.#.#.#.###.#.#.#.#####.#.#.#.###v#######.#######.###.#.#.###########.#.###########.#.#.###.###.# +#.....#...#...#.#.#.......#.#.#.#...###...#...#.#.#.#...#...#.......#.#.#...#...#...#.........#...#...#...#...###...#####...###...#.....#...# +#####.#.#.#.#.#.#.#.#######.#.#.###.###########.#.#.#.###############.#.###.###.#.#.###########.#######.#.#.#.###########.#.#############.### +#...#...#...#.#.#.#...#...#.#.#.###...#...#.....#.#.#...#.............#...#.###...#.#...###...#.........#...#.....#...#...#.....#.........### +#.#.#########.#.#.###.#.#.#.#.#.#####.#.#.#.#####.#.###.#.###############.#.#######.#.#.###.#.###################.#.#.#.#######.#.########### +#.#...........#.#.###...#...#...#...#...#.#.......#...#.#.....#...#######.#.#.......#.#.#...#.....#...#...........#.#.#...#.....#...#####...# +#.#############.#.###############.#.#####.###########.#.#####.#.#.#######.#.#.#######.#.#.#######.#.#.#.###########.#.###.#.#######.#####.#.# +#.#...........#...#.....#.....#...#...#...#.....#...#...#...#...#.......#...#.....###.#.#.#.......#.#.#...#...#.....#.#...#...#...#.....#.#.# +#.#.#########.#####.###.#.###.#.#####.#v###.###.#.#.#####.#.###########.#########.###.#.#.#.#######.#.###v#.#.#.#####.#.#####.#.#.#####.#.#.# +#...#.........#...#...#.#...#.#.....#.>.>.#.#...#.#.#.....#.#...........#...#...#.#...#.#.#.#...#...#.#.>.>.#.#...#...#.....#.#.#.#.....#.#.# +#####.#########.#.###.#.###.#.#####.###v#.#.#.###.#.#.#####.#.###########.#.#.#.#v#.###.#.#.#.#.#.###.#.#v###.###.#.#######.#.#.#.#v#####.#.# +#.....#.........#...#.#.###.#.#...#...#.#...#...#.#.#...#...#.......###...#.#.#.>.>.#...#.#...#.#...#.#.#...#...#.#.#...#...#.#.#.>.#...#.#.# +#.#####.###########.#.#.###.#.#.#.###.#.#######.#.#.###.#.#########.###.###.#.###v###.###.#####.###.#.#.###.###.#.#.#.#.#.###.#.###v#.#.#.#.# +#.....#.#...........#.#...#.#.#.#.###.#.....#...#.#.#...#...#.....#...#...#.#.###...#...#...#...#...#...#...###.#.#.#.#.#.#...#...#...#...#.# +#####.#.#.###########.###.#.#.#.#.###.#####.#.###.#.#.#####.#.###.###.###.#.#.#####.###.###.#.###.#######.#####.#.#.#.#.#.#.#####.#########.# +#.....#.#...#...#...#.#...#.#.#.#.....#.....#...#.#.#.....#.#.#...#...#...#.#.#.....###.#...#...#.#.......#...#...#...#.#.#.#...#.###...#...# +#.#####.###.#.#.#.#.#.#.###.#.#.#######.#######.#.#.#####.#.#.#.###v###.###.#.#.#######.#.#####.#.#.#######.#.#########.#.#.#.#.#.###.#.#.### +#.#...#...#.#.#...#.#.#.#...#...###...#...#.....#.#...#...#.#.#.#.>.>.#...#...#...#...#.#.....#.#.#.........#.........#.#.#.#.#.#.#...#...### +#.#.#.###.#.#.#####.#.#.#.#########.#.###.#.#####.###.#.###.#.#.#.#v#.###.#######.#.#.#.#####.#.#.###################.#.#.#.#.#.#.#.######### +#...#...#.#...###...#.#...#####...#.#.#...#.....#.#...#...#...#...#.#.#...###...#...#.#.......#.#.#...................#.#.#...#...#.........# +#######.#.#######v###.#########.#.#.#.#.#######.#.#.#####.#########.#.#.#####.#.#####.#########.#.#.###################.#.#################.# +#.......#.#.....#.>.#...###.....#...#...###.....#.#.......#.......#.#...#.....#.......#...#...#...#...................#.#.#.................# +#.#######.#.###.#v#.###.###.###############.#####.#########.#####.#.#####.#############.#.#.#.#######################.#.#.#.################# +#.......#.#.#...#.#...#...#...........#...#.......###...###...#...#.....#.#.......#...#.#...#.......###...............#...#.............#...# +#######.#.#.#.###.###.###.###########.#.#.###########.#.#####.#.#######.#.#.#####.#.#.#.###########.###.###############################.#.#.# +#...###...#.#.#...#...#...###.........#.#...#.......#.#.#.....#.......#.#.#.#.....#.#.#.#...........#...#.............#.........#.......#.#.# +#.#.#######.#.#.###.###.#####.#########.###.#.#####.#.#.#.###########.#.#.#.#.#####.#.#.#.###########.###.###########.#.#######.#.#######.#.# +#.#...#...#.#.#...#.....#...#.....#...#.#...#.....#...#.#.....#.....#.#.#.#.#.#...#.#...#.#.....#...#...#.#...........#.......#...#.....#.#.# +#.###.#.#.#.#.###.#######.#.#####.#.#.#.#.#######.#####.#####.#.###.#.#.#.#.#.#.#.#.#####.#.###.#.#.###.#.#.#################.#####.###.#.#.# +#...#...#...#...#.....###.#.......#.#.#.#.#...###.#.....#...#...###.#...#...#...#...#.....#.#...#.#...#...#.......###...#.....#.....###...#.# +###.###########.#####.###.#########.#.#.#.#.#.###.#.#####.#.#######v#################.#####.#.###.###.###########.###.#.#.#####.###########.# +###.#...#.....#.#...#.#...#.....###.#.#.#.#.#...#.#...#...#.#...#.>.>.#...#...#.......#.....#...#.#...#.....#...#...#.#.#.......#...#.......# +###.#.#.#.###.#.#.#.#.#.###.###.###.#.#.#.#.###.#.###.#.###.#.#.#.#v#.#.#.#.#.#.#######.#######.#.#.###.###.#.#.###.#.#.#########.#.#.####### +###...#.#.###.#...#...#.....#...#...#...#...#...#...#.#.#...#.#...#.#.#.#.#.#.#.........#.......#.#.###...#...#.....#.#.#...#...#.#.#.......# +#######.#.###v###############.###.###########.#####.#.#.#.###.#####.#.#.#.#.#.###########.#######.#.#####.###########.#.#.#.#.#.#.#.#######.# +###...#...###.>.#...#.......#...#.#...#...###.#...#.#...#...#.###...#.#.#...#...#...#.....#...#...#.....#.........#...#.#.#.#.#.#.#...#.....# +###.#.#######v#.#.#.#.#####.###.#.#.#.#.#.###.#.#.#.#######.#.###.###.#.#######.#.#.#.#####.#.#.#######.#########.#.###.#.#.#.#.#.###.#.##### +###.#.#...#...#.#.#.#.#.....###.#...#...#...#.#.#.#.....#...#.#...###...#.......#.#.#.#...#.#.#...#.....#...#.....#.#...#.#.#.#.#.#...#...### +###.#.#.#.#.###.#.#.#.#.#######v###########.#.#.#.#####.#.###.#.#########.#######.#.#.#.#.#.#.###.#.#####.#.#v#####.#.###.#.#.#.#.#.#####v### +#...#...#.#...#.#.#.#.#...#...>.>.........#.#...#.#.....#.....#.......###...#...#.#.#...#.#.#...#.#.#.....#.>.>...#.#.#...#.#.#.#.#.#...>.### +#.#######.###.#.#.#.#.###.#.###v#########.#.#####.#.#################.#####.#.#.#.#.#####.#.###.#.#.#.#######v###.#.#.#.###.#.#.#.#.#.###v### +#.......#.....#...#.#...#.#...#.........#.#.....#...#...#...###.....#...#...#.#.#.#.#...#.#...#...#.#.#.......#...#.#...#...#.#...#.#.#...### +#######.###########.###.#.###.#########.#.#####.#####.#.#.#.###.###.###.#.###.#.#.#.#.#.#v###.#####.#.#.#######.###.#####.###.#####.#.#.##### +###...#.........#...#...#.....###.......#.#...#.#.....#...#.#...###.#...#...#.#.#.#...#.>.>.#...#...#.#...#...#...#.....#.#...#...#.#.#.....# +###.#.#########.#.###.###########.#######.#.#.#.#.#########.#.#####.#.#####.#.#.#.#######v#.###.#.###.###.#.#.###.#####.#.#.###.#.#.#.#####.# +#...#.#...#.....#.....#####.......#######...#.#.#.........#...#...#...#...#...#...#...###.#...#.#.#...###...#...#.......#...#...#...#.#.....# +#.###.#.#.#.###############.#################.#.#########.#####.#.#####.#.#########.#.###.###.#.#.#.###########.#############.#######.#.##### +#...#...#...#.......#.......#...............#.#.#.........#.....#...#...#.......#...#...#...#.#.#.#.#.....#.....#.....#.....#.........#.....# +###.#########.#####.#.#######.#############.#.#.#.#########.#######.#.#########.#.#####.###.#.#.#.#.#.###.#.#####.###.#.###.###############.# +#...#.........#.....#.......#.#.....#...#...#...#.........#.#.......#...#.....#.#...#...#...#.#.#.#.#...#.#.......#...#...#...........###...# +#.###.#########.###########.#.#.###.#.#.#.###############.#.#.#########.#.###.#.###.#.###.###.#.#.#.###.#.#########.#####.###########.###.### +#...#.#.........#####.......#.#...#...#.#...#...........#...#.#.....#...#.#...#.....#...#.###...#...###.#...........#####...........#...#.### +###.#.#.#############.#######.###.#####.###.#.#########.#####.#.###.#.###.#.###########.#.#############.###########################.###.#.### +###.#.#.#...#.......#.......#...#.....#...#.#.........#.#...#...#...#.....#...........#...#...#...#.....#.........#...###...###.....#...#...# +###.#.#.#.#v#.#####.#######.###.#####.###.#.#########.#.#.#.#####.###################.#####.#.#.#.#.#####.#######.#.#.###.#.###.#####.#####.# +###...#...#.>.#...#...#...#.....#...#...#...###.......#...#.....#...#...###...........###...#...#.#.....#.#.......#.#.#...#...#...###.....#.# +###########v###.#.###.#.#.#######.#.###.#######.###############.###.#.#.###.#############.#######.#####.#.#.#######.#.#.#####.###.#######.#.# +#...........#...#.....#.#.###.....#...#...#...#...#.....#.....#...#.#.#...#...#.....#.....#.......#####...#...#...#.#.#.....#...#.....#...#.# +#.###########.#########.#.###.#######.###.#.#.###.#.###.#.###.###.#.#.###.###v#.###.#.#####.#################.#.#.#.#.#####.###.#####.#.###.# +#...........#.#...#.....#...#.......#.#...#.#.###...#...#.###...#...#...#.#.>.>.#...#...#...###...###...#...#...#...#.#...#...#.#.....#.....# +###########.#.#.#.#.#######.#######.#.#.###.#.#######.###.#####.#######.#.#.#v###.#####.#.#####.#.###.#.#.#.#########.#.#.###.#.#.########### +#...#.......#.#.#.#...#.....#.......#...#...#.#...#...#...#.....#.....#.#.#.#.###.....#.#.....#.#...#.#.#.#.#.........#.#.#...#.#...........# +#.#.#.#######.#.#.###.#.#####.###########.###.#.#.#.###.###.#####.###.#.#.#.#.#######.#.#####.#.###.#.#.#.#.#.#########.#.#.###.###########.# +#.#.#.......#...#...#.#.....#.........#...#...#.#.#.....###.....#...#.#.#.#.#.#.....#...#.....#.#...#.#.#.#.#.#.....#...#...###.....#.....#.# +#.#.#######.#######.#.#####.#########.#.###.###.#.#############.###.#.#.#.#.#.#.###.#####.#####.#.###.#.#.#.#v#.###.#.#############.#.###.#.# +#.#.........#...#...#.#.....#...#.....#...#.....#.#.......#.....#...#.#.#.#.#.#.###.....#.#...#.#...#.#.#.#.>.>.#...#.............#.#...#.#.# +#.###########.#.#.###.#.#####.#.#v#######.#######.#.#####.#.#####.###.#.#.#.#.#.#######.#.#.#.#.###.#.#.#.###v###.###############.#.###.#.#.# +#...........#.#.#...#.#...#...#.>.>...###.....#...#...#...#...#...#...#.#.#.#...#####...#.#.#.#...#.#.#.#.###.###.#...#...#.....#.#.#...#...# +###########.#.#.###.#.###.#.#####v###.#######.#.#####.#.#####v#.###.###.#.#.#########.###.#.#.###.#.#.#.#.###.###.#.#.#.#.#v###.#.#.#.####### +#####...###...#.#...#...#...#.....###...#...#.#.......#.....>.>.###...#.#.#...#...#...###...#.#...#.#.#...#...#...#.#.#.#.>.###...#...###...# +#####.#.#######.#.#####.#####.#########.#.#.#.###############v#######.#.#.###.#.#.#.#########.#.###.#.#####.###.###.#.#.###v#############.#.# +#.....#.........#...#...#...#.....#...#.#.#...###...#.......#.#.....#...#.....#.#...#...###...#.###...###...###.....#.#.###.......#...#...#.# +#.#################.#.###.#.#####.#.#.#.#.#######.#.#.#####.#.#.###.###########.#####.#.###.###.#########.###########.#.#########.#.#.#.###.# +#.#.............###.#.###.#.....#...#.#...###...#.#.#.....#...#...#.....#...#...#.....#...#.....#...#...#...###.....#...#.........#.#.#.#...# +#.#.###########.###.#.###.#####.#####.#######.#.#.#.#####.#######.#####.#.#.#.###.#######.#######.#.#.#.###.###.###.#####.#########.#.#.#.### +#...#.....#...#...#...#...#.....#...#.......#.#.#.#...###.....###.#.....#.#.#.....#.....#.....#...#...#...#.....#...#...#.......#...#...#...# +#####.###.#.#.###.#####.###.#####.#.#######.#.#.#.###.#######.###.#.#####.#.#######.###.#####.#.#########.#######.###.#.#######.#.#########.# +#...#...#.#.#...#...###.#...#...#.#.###.....#.#.#...#.#.......#...#.#...#.#.....###...#.......#.........#.....#...###.#.........#.#...#.....# +#.#.###.#.#.###.###.###.#.###.#.#.#.###v#####.#.###.#.#v#######.###.#.#.#.#####.#####.#################.#####.#.#####.###########.#.#.#.##### +#.#.###.#...#...#...#...#...#.#.#.#.#.>.>...#.#.#...#.>.>...#...#...#.#.#.#.....#...#.....#.....#...###.....#.#.....#...#.....###.#.#...##### +#.#.###.#####.###.###.#####.#.#.#.#.#.#####.#.#.#.#########.#.###.###.#.#.#.#####.#.#####.#.###.#.#.#######.#.#####.###.#.###.###.#.######### +#.#.....#...#.....###...###.#.#.#.#.#...#...#.#.#.###...#...#.###...#.#.#.#.#...#.#.......#.#...#.#...#.....#.......###.#.###.....#...#...### +#.#######.#.###########.###.#.#.#.#.###.#.###.#.#.###.#.#.###.#####.#.#.#.#.#.#.#.#########.#.###.###.#.###############.#.###########.#.#.### +#.#.....#.#.#.....#...#...#.#.#.#.#...#.#.#...#.#...#.#.#...#.....#...#...#.#.#.#.....#...#.#.###.#...#.....#...#.....#...#.........#...#...# +#.#.###.#.#.#.###.#.#.###.#.#.#.#.###.#.#.#.###.###.#.#.###.#####.#########.#.#.#####.#.#.#.#.###.#.#######v#.#.#.###.#####.#######.#######.# +#.#.###...#...#...#.#.#...#.#.#.#...#.#.#.#.###...#.#.#.....#...#...#.......#.#.#...#...#.#.#...#.#...#...>.>.#...#...#.....#...###.........# +#.#.###########.###.#.#.###.#.#.###.#.#.#.#.#####.#.#.#######.#.###.#.#######.#.#.#.#####v#.###.#.###.#.###########.###.#####.#.############# +#...###.......#...#.#.#...#...#.#...#...#...#.....#.#...#...#.#.#...#.......#.#.#.#.#...>.>.###.#.#...#...#.........###.#...#.#.........#...# +#######.#####.###.#.#.###.#####.#.###########.#####.###.#.#.#.#.#.#########.#.#.#.#.#.#########.#.#.#####.#.###########.#.#.#.#########.#.#.# +#.......#...#.....#.#.#...#.....#...........#.....#.#...#.#.#.#.#...#.......#.#.#.#.#.....#.....#.#...#...#.......#...#...#...#.........#.#.# +#.#######.#.#######.#.#.###.###############.#####.#.#.###.#.#.#.###.#.#######.#.#.#.#####.#.#####.###.#.#########.#.#.#########.#########.#.# +#.#.......#.#.....#.#.#...#.#...#.....#...#.###...#.#...#.#.#.#...#.#...#...#.#...#.#.....#.....#.#...#.#.........#.#.###...###.......#...#.# +#.#.#######.#.###.#.#.###.#.#.#.#.###.#.#.#.###.###.###.#.#.#.###.#.###.#.#.#.#####.#.#########.#.#.###.#.#########.#.###.#.#########v#.###.# +#.#.#.......#...#.#.#...#.#.#.#.#.###.#.#.#...#.#...#...#.#.#...#.#.###.#.#.#.....#.#.....#.....#.#...#.#...#...#...#.#...#...#...#.>.#...#.# +#.#.#.#########.#.#.###.#.#.#.#.#.###.#.#.###.#.#.###.###.#.###.#.#.###.#.#.#####.#.#####.#.#####.###.#.###.#.#.#.###.#.#####.#.#.#.#v###.#.# +#...#...........#...###...#...#...###...#.....#...###.....#.....#...###...#.......#.......#.......###...###...#...###...#####...#...#.....#.# +###########################################################################################################################################.# \ No newline at end of file diff --git a/output/23-1.txt b/output/23-1.txt new file mode 100644 index 0000000..4d2b256 --- /dev/null +++ b/output/23-1.txt @@ -0,0 +1 @@ +2042 \ No newline at end of file diff --git a/output/23-2.txt b/output/23-2.txt new file mode 100644 index 0000000..49ed577 --- /dev/null +++ b/output/23-2.txt @@ -0,0 +1 @@ +6466 \ No newline at end of file diff --git a/src/main/scala/adventofcode/solutions/Day23.scala b/src/main/scala/adventofcode/solutions/Day23.scala new file mode 100644 index 0000000..c38ecde --- /dev/null +++ b/src/main/scala/adventofcode/solutions/Day23.scala @@ -0,0 +1,93 @@ +package adventofcode.solutions + +import adventofcode.Definitions.* + +@main def Day23 = Day(23) { (input, part) => + + case class Vec(i: Int, j: Int): + infix def +(that: Vec): Vec = Vec(i + that.i, j + that.j) + def unary_- : Vec = Vec(-i, -j) + + val directions = + val range = -1 to 1 + for + i <- range + j <- range + if (i == 0) != (j == 0) + yield Vec(i, j) + val directionsSet = directions.toSet + + val map = input.toLines.map(_.map { + case '.' => Some(None) + case '#' => None + case '^' => Some(Some(Vec(-1, 0))) + case '>' => Some(Some(Vec(0, 1))) + case 'v' => Some(Some(Vec(1, 0))) + case '<' => Some(Some(Vec(0, -1))) + }) + + val (start, end) = (Vec(0, 1), Vec(map.size - 1, map.head.size - 2)) + val startDirection = Vec(1, 0) + + def inBounds(point: Vec): Boolean = + map.indices.contains(point.i) && map(point.i).indices.contains(point.j) + + def longestWithSlopes(positions: Set[(Vec, Vec)], i: Int): Int = + if positions.nonEmpty then + val newPositions = positions.flatMap((p, d0) => + (directionsSet - -d0) + .map(d1 => (p + d1, d1)) + .filter((p, _) => inBounds(p)) + .filter { (p, d) => + val tile = map(p.i)(p.j) + tile.exists(_.forall(_ == d)) + } + ) + longestWithSlopes(newPositions, i + 1) + else + i - 1 + + part(1) = longestWithSlopes(Set(start -> startDirection), 0) + + val intersectionsSet = + val intersections = + for + i <- map.indices + j <- map(i).indices + p0 = Vec(i, j) + if (directions.map(p0 + _) :+ p0).filter(inBounds).count(p1 => map(p1.i)(p1.j).nonEmpty) > 3 + yield p0 + intersections.toSet + + def reachableIntersections(current: Set[Vec], history: Map[Vec, Int], i: Int): Map[Vec, Int] = + if current.nonEmpty then + val newCurrent = current + .flatMap(p => directions.map(p + _)) + .filter(inBounds) + .filter(p => map(p.i)(p.j).nonEmpty) + .diff(history.keySet) + reachableIntersections(newCurrent.diff(intersectionsSet), history ++ newCurrent.map(_ -> i).toMap, i + 1) + else + history.view.filterKeys(intersectionsSet.contains).toMap + + val intersectionsGraph = intersectionsSet + .map(intersection => intersection -> (reachableIntersections(Set(intersection), Map(intersection -> 0), 1) - intersection)).toMap + + val startEndIntersections = Seq(start, end).map(p => reachableIntersections(Set(p), Map(p -> 0), 0).head) + val (startIntersection, endIntersection) = startEndIntersections.map(_._1) match + case Seq(se, ee) => (se, ee) + val initialCost = startEndIntersections.map(_._2 + 1).sum + + def longestIntersectionPath(current: Vec, history: Set[Vec], length: Int): Int = + if current != endIntersection then + val newHistory = history + current + intersectionsGraph(current) + .filter((v, _) => !newHistory.contains(v)) + .map((v, cost) => longestIntersectionPath(v, newHistory, length + cost)) + .maxOption.getOrElse(0) + else + length + + part(2) = longestIntersectionPath(startIntersection, Set.empty, initialCost) + +}