From f62c35bf618fa322cd2bf541517f87a378a7bcc5 Mon Sep 17 00:00:00 2001 From: Florian Cassayre Date: Tue, 31 Dec 2024 12:06:06 +0100 Subject: [PATCH] Solved day 20 --- README.md | 2 +- input/20.txt | 141 ++++++++++++++++++ output/20-1.txt | 1 + output/20-2.txt | 1 + .../scala/adventofcode/solutions/Day20.scala | 55 +++++++ 5 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 input/20.txt create mode 100644 output/20-1.txt create mode 100644 output/20-2.txt create mode 100644 src/main/scala/adventofcode/solutions/Day20.scala diff --git a/README.md b/README.md index 3d734d4..ff3753b 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ _My solutions to the 2024 edition of [Advent of Code](https://adventofcode.com/2 | **[17](https://adventofcode.com/2024/day/17)** | [solution](src/main/scala/adventofcode/solutions/Day17.scala) | | **[18](https://adventofcode.com/2024/day/18)** | [solution](src/main/scala/adventofcode/solutions/Day18.scala) | | **[19](https://adventofcode.com/2024/day/19)** | [solution](src/main/scala/adventofcode/solutions/Day19.scala) | -| **[20](https://adventofcode.com/2024/day/20)** | [](src/main/scala/adventofcode/solutions/Day20.scala) | +| **[20](https://adventofcode.com/2024/day/20)** | [solution](src/main/scala/adventofcode/solutions/Day20.scala) | | **[21](https://adventofcode.com/2024/day/21)** | [](src/main/scala/adventofcode/solutions/Day21.scala) | | **[22](https://adventofcode.com/2024/day/22)** | [](src/main/scala/adventofcode/solutions/Day22.scala) | | **[23](https://adventofcode.com/2024/day/23)** | [](src/main/scala/adventofcode/solutions/Day23.scala) | diff --git a/input/20.txt b/input/20.txt new file mode 100644 index 0000000..3e5c376 --- /dev/null +++ b/input/20.txt @@ -0,0 +1,141 @@ +############################################################################################################################################# +#.......###.....###...###.......#...#.....#...#...#...#.....#...###.....###.......###...###.....#...#...#.....###...............#.........### +#.#####.###.###.###.#.###.#####.#.#.#.###.#.#.#.#.#.#.#.###.#.#.###.###.###.#####.###.#.###.###.#.#.#.#.#.###.###.#############.#.#######.### +#.#...#.....#...#...#...#.....#.#.#.#.#...#.#.#.#...#.#...#.#.#...#...#...#.....#.....#.#...#...#.#...#.#...#...#...#.........#.#.......#...# +#.#.#.#######.###.#####.#####.#.#.#.#.#.###.#.#.#####.###.#.#.###.###.###.#####.#######.#.###.###.#####.###.###.###.#.#######.#.#######.###.# +#...#.......#...#...#...#.....#.#.#.#.#...#.#...#.....#...#.#.#...#...#...#...#.......#...#...#...#.....###...#.#...#...#...#...###.....#...# +###########.###.###.#.###.#####.#.#.#.###.#.#####.#####.###.#.#.###.###.###.#.#######.#####.###.###.#########.#.#.#####.#.#.#######.#####.### +#.........#...#...#.#...#.....#.#.#.#.#...#.....#.#...#...#...#.....#...#...#.###...#.....#...#.#...#...#.....#...#.....#.#...###...#...#...# +#.#######.###.###.#.###.#####.#.#.#.#.#.#######.#.#.#.###.###########.###.###.###.#.#####.###.#.#.###.#.#.#########.#####.###.###.###.#.###.# +#.....#...###...#.#...#.......#.#.#...#.....#...#.#.#.#...#...........###.#...#...#.......#...#.#...#.#.#.....#...#.#...#.#...#...#...#.....# +#####.#.#######.#.###.#########.#.#########.#.###.#.#.#.###.#############.#.###.###########.###.###.#.#.#####.#.#.#.#.#.#.#.###.###.######### +#.....#...#.....#.....#...#...#.#.#.........#...#.#.#.#.#...#...#...#...#.#.###.....#.....#...#.#...#.#.#...#.#.#.#.#.#.#.#.#...#...###.....# +#.#######.#.###########.#.#.#.#.#.#.###########.#.#.#.#.#.###.#.#.#.#.#.#.#.#######.#.###.###.#.#.###.#.#.#.#.#.#.#.#.#.#.#.#.###.#####.###.# +#.......#.#.....#...#...#...#.#...#.....#...###.#.#.#.#.#.....#.#.#.#.#.#.#.#.....#...###...#.#.#.#...#.#.#.#.#.#...#.#.#.#.#.#...###...#...# +#######.#.#####.#.#.#.#######.#########.#.#.###.#.#.#.#.#######.#.#.#.#.#.#.#.###.#########.#.#.#.#.###.#.#.#.#.#####.#.#.#.#.#.#####.###.### +###...#.#.....#...#...#...#...#.........#.#.#...#.#.#.#...#.....#.#.#.#.#.#.#...#...#.......#...#.#.#...#.#.#.#...#...#...#...#.....#...#.### +###.#.#.#####.#########.#.#.###.#########.#.#.###.#.#.###.#.#####.#.#.#.#.#.###.###.#.###########.#.#.###.#.#.###.#.###############.###.#.### +#...#...#.....#.....#...#.#...#.#...###...#.#...#.#.#.#...#.#...#.#.#.#.#.#...#.#...#.........#...#.#...#.#...#...#...#.............#...#...# +#.#######.#####.###.#.###.###.#.#.#.###.###.###.#.#.#.#.###.#.#.#.#.#.#.#.###.#.#.###########.#.###.###.#.#####.#####.#.#############.#####.# +#.....#...#...#.#...#...#.###.#.#.#...#...#...#.#.#.#.#...#...#.#.#.#.#.#.#...#.#...###.......#.....#...#...#...###...#.............#.#.....# +#####.#.###.#.#.#.#####.#.###.#.#.###.###.###.#.#.#.#.###.#####.#.#.#.#.#.#.###.###.###.#############.#####.#.#####.###############.#.#.##### +#...#.#...#.#...#.#...#.#...#.#.#.#...###...#.#.#.#.#.#...#.....#.#.#.#...#.#...#...#...#...........#...#...#...#...#...#...........#.#.....# +#.#.#.###.#.#####.#.#.#.###.#.#.#.#.#######.#.#.#.#.#.#.###.#####.#.#.#####.#.###.###.###.#########.###.#.#####.#.###.#.#.###########.#####.# +#.#.#.#...#.....#.#.#.#...#.#.#.#.#.###...#.#...#.#.#.#.#...#...#.#.#.#.....#...#.###.....#...#...#.#...#...#...#.#...#...#...###...#.#.....# +#.#.#.#.#######.#.#.#.###.#.#.#.#.#.###.#.#.#####.#.#.#.#.###.#.#.#.#.#.#######.#.#########.#.#.#.#.#.#####.#.###.#.#######.#.###.#.#.#.##### +#.#...#.........#...#.....#.#.#.#.#.#...#.#.....#.#.#...#.###.#.#.#.#.#...#...#.#.#.....#...#.#.#.#.#.#...#.#...#.#.....###.#...#.#...#.....# +#.#########################.#.#.#.#.#.###.#####.#.#.#####.###.#.#.#.#.###.#.#.#.#.#.###.#.###.#.#.#.#.#.#.#.###.#.#####.###.###.#.#########.# +#.#.......................#...#.#.#.#.#...#.....#...#...#.#...#...#.#.#...#.#...#.#...#.#...#...#.#.#.#.#.#...#...#...#...#...#.#.#.........# +#.#.#####################.#####.#.#.#.#.###.#########.#.#.#.#######.#.#.###.#####.###.#.###.#####.#.#.#.#.###.#####.#.###.###.#.#.#.######### +#.#.#...................#.....#.#.#.#.#...#.....#.....#...#.......#...#...#.....#.#...#...#.....#...#.#.#...#.#.....#...#.....#...#.....#...# +#.#.#.#################.#####.#.#.#.#.###.#####.#.###############.#######.#####.#.#.#####.#####.#####.#.###.#.#.#######.###############.#.#.# +#...#.........#...#...#.......#...#.#...#...#...#...#...#...#...#.#.......#...#.#.#.#...#.#...#.#...#.#.#...#.#.......#.#...#.....#.....#.#.# +#############.#.#.#.#.#############.###.###.#.#####.#.#.#.#.#.#.#.#.#######.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.###.#######.#.#.#.#.###.#.#####.#.# +#...........#...#.#.#.........#...#.###.#...#...#...#.#.#.#.#.#.#.#.#...###.#.#.#.#...#.#.#.#.#...#.#.#.#.....#...#...#.#.#.#...#.#.......#.# +#.#########.#####.#.#########.#.#.#.###.#.#####.#.###.#.#.#.#.#.#.#.#.#.###.#.#.#.#####.#.#.#.#####.#.#.#######.#.#.###.#.#.###.#.#########.# +#.........#.....#...#...#.....#.#.#...#.#.#...#.#...#.#.#.#.#.#.#.#...#...#.#.#.#...#...#.#.#.....#.#.#.#.......#...###...#.#...#.#.....#...# +#########.#####.#####.#.#.#####.#.###.#.#.#.#.#.###.#.#.#.#.#.#.#.#######.#.#.#.###.#.###.#.#####.#.#.#.#.#################.#.###.#.###.#.### +#.......#.....#.#.....#...#...#.#...#.#.#.#.#.#.#...#.#.#.#.#.#.#.....#...#.#.#...#.#...#.#.....#...#.#.#.....###...#.....#.#...#.#...#...### +#.#####.#####.#.#.#########.#.#.###.#.#.#.#.#.#.#.###.#.#.#.#.#.#####.#.###.#.###.#.###.#.#####.#####.#.#####.###.#.#.###.#.###.#.###.####### +#.....#.......#...#.......#.#...###.#.#.#.#.#.#.#...#.#.#.#.#.#.#.....#.#...#...#.#.....#.#.....#...#...#...#.....#...#...#.#...#.....#.....# +#####.#############.#####.#.#######.#.#.#.#.#.#.###.#.#.#.#.#.#.#.#####.#.#####.#.#######.#.#####.#.#####.#.###########.###.#.#########.###.# +#...#...#...#...#...#.....#...#.....#...#...#.#...#...#.#.#.#.#.#...###.#.....#.#.....###...#.....#.....#.#.......#.....###...###...###.#...# +#.#.###.#.#.#.#.#.###.#######.#.#############.###.#####.#.#.#.#.###.###.#####.#.#####.#######.#########.#.#######.#.#############.#.###.#.### +#.#.###...#...#...###...#...#.#.....#...#...#.....#.....#.#...#.#...#...#...#.#.#...#.#.....#.........#.#.....#...#.#...#...#...#.#.....#...# +#.#.###################.#.#.#.#####.#.#.#.#.#######.#####.#####.#.###.###.#.#.#.#.#.#.#.###.#########.#.#####.#.###.#.#.#.#.#.#.#.#########.# +#.#.#...#.....###...###...#...#...#...#...#.......#.#...#.....#...###...#.#.#.#.#.#.#.#...#.#...#...#.#.......#.....#.#.#.#.#.#...#...#...#.# +#.#.#.#.#.###.###.#.###########.#.###############.#.#.#.#####.#########.#.#.#.#.#.#.#.###.#.#.#.#.#.#.###############.#.#.#.#.#####.#.#.#.#.# +#.#.#.#.#.#...#...#...#.....#...#.........#...#...#...#.....#.....#...#.#.#.#.#...#.#.#...#...#...#...#...###...#.....#...#...#.....#...#.#.# +#.#.#.#.#.#.###.#####.#.###.#.###########.#.#.#.###########.#####.#.#.#.#.#.#.#####.#.#.###############.#.###.#.#.#############.#########.#.# +#.#...#...#.#...#...#...#...#...........#.#.#.#.......#.....#...#.#.#...#.#.#.....#...#.#...#.......#...#.....#...#...#.....#...###...###.#.# +#.#########.#.###.#.#####.#############.#.#.#.#######.#.#####.#.#.#.#####.#.#####.#####.#.#.#.#####.#.#############.#.#.###.#.#####.#.###.#.# +#.........#.#.....#.....#...............#...#.......#.#...#...#.#.#...#...#.......#...#.#.#.#...#...#...#...........#.#.#...#.......#...#.#.# +#########.#.###########.###########################.#.###.#.###.#.###.#.###########.#.#.#.#.###.#.#####.#.###########.#.#.#############.#.#.# +#...###...#.............#...#...#.....#...#.......#.#.#...#...#.#.#...#.#...........#...#.#.#...#.......#...........#...#.....#.........#...# +#.#.###.#################.#.#.#.#.###.#.#.#.#####.#.#.#.#####.#.#.#.###.#.###############.#.#.#####################.#########.#.############# +#.#...#...#...#.....#...#.#.#.#...#...#.#.#.#.....#...#...#...#...#...#.#.#...#...#.....#.#.#.#.....#.............#.........#.#.......#...### +#.###.###.#.#.#.###.#.#.#.#.#.#####.###.#.#.#.###########.#.#########.#.#.#.#.#.#.#.###.#.#.#.#.###.#.###########.#########.#.#######.#.#.### +#...#.....#.#...#...#.#.#.#...#...#.....#...#...#...#####...#...#...#.#.#.#.#...#.#.###...#...#...#...#.........#...#.......#.......#...#...# +###.#######.#####.###.#.#.#####.#.#############.#.#.#########.#.#.#.#.#.#.#.#####.#.#############.#####.#######.###.#.#############.#######.# +#...#...#...#...#.....#...###...#.........#...#...#...###.....#...#.#...#...#.....#.........#...#...#...#.......###.#.#...#.......#.......#.# +#.###.#.#.###.#.#############.###########.#.#.#######.###.#########.#########.#############.#.#.###.#.###.#########.#.#.#.#.#####.#######.#.# +#.....#...#...#...#.....#...#...........#...#.#.....#.....#...#...#.....#.....#.....#.......#.#...#...#...#.......#...#.#...#.....###...#...# +###########.#####.#.###.#.#.###########.#####.#.###.#######.#.#.#.#####.#.#####.###.#.#######.###.#####.###.#####.#####.#####.#######.#.##### +#.....#...#.....#.#...#.#.#.#...#.....#.....#.#...#.#...#...#.#.#...#...#.#.....#...#.....###...#.#...#.....#.....#...#.#.....###...#.#.#...# +#.###.#.#.#####.#.###.#.#.#.#.#.#.###.#####.#.###.#.#.#.#.###.#.###.#.###.#.#####.#######.#####.#.#.#.#######.#####.#.#.#.#######.#.#.#.#.#.# +#...#.#.#...#...#.....#.#.#.#.#.#...#...#...#.....#...#.#.###...###.#...#...#...#...#...#.#.....#...#...#.....#.....#...#.........#...#...#.# +###.#.#.###.#.#########.#.#.#.#.###.###.#.#############.#.#########.###.#####.#.###.#.#.#.#.###########.#.#####.###########################.# +#...#...#...#.#...#...#...#...#.#...#...#.............#.#.......#...#...###...#.....#.#...#...........#...#.....#.........#.................# +#.#######.###.#.#.#.#.#########.#.###.###############.#.#######.#.###.#####.#########.###############.#####.#####.#######.#.################# +#.......#...#...#...#.........#.#...#...........#.....#.#...#...#...#.#.....#.........#.........#...#.....#...#...#...###...###...#.....#...# +#######.###.#################.#.###.###########.#.#####.#.#.#.#####.#.#.#####.#########.#######.#.#.#####.###.#.###.#.#########.#.#.###.#.#.# +###...#...#.......#...#.......#...#...###...###...#...#...#...#...#...#.#.....#.........#.....#.#.#.#...#.....#.#...#.....#...#.#.#.#...#.#.# +###.#.###.#######.#.#.#.#########.###.###.#.#######.#.#########.#.#####.#.#####.#########.###.#.#.#.#.#.#######.#.#######.#.#.#.#.#.#.###.#.# +#...#.....#.....#...#...#...#...#.....#...#.....#...#.#.....###.#.#...#...#...#...........###.#...#...#.........#.#.....#...#...#...#.....#.# +#.#########.###.#########.#.#.#.#######.#######.#.###.#.###.###.#.#.#.#####.#.###############.###################.#.###.###################.# +#...#...#...###...#.....#.#.#.#.....###.#.....#...#...#.#...#...#.#.#...#...#.#...#...###.....#.................#.#.###...#...#.....#.......# +###.#.#.#.#######.#.###.#.#.#.#####.###.#.###.#####.###.#.###.###.#.###.#.###.#.#.#.#.###.#####.###############.#.#.#####.#.#.#.###.#.####### +#...#.#.#.#.......#...#...#...#...#.....#...#.#...#.....#...#.#...#.#...#...#.#.#.#.#...#.......#...............#.#.....#...#...#...#.....### +#.###.#.#.#.#########.#########.#.#########.#.#.#.#########.#.#.###.#.#####.#.#.#.#.###.#########.###############.#####.#########.#######.### +#.#...#.#.#...#.......###.....#.#...........#...#.....#.....#.#.#...#.#...#.#...#.#.#...#...#...#...........#.....#...#.###...###.......#...# +#.#.###.#.###.#.#########.###.#.#####################.#.#####.#.#.###.#.#.#.#####.#.#.###.#.#.#.###########.#.#####.#.#.###.#.#########.###.# +#.#...#...###...#...#...#...#.#...........#...#...###...#...#.#.#...#.#.#.#.#...#.#.#.....#...#...###.......#.#.....#...#...#...#...###.....# +#.###.###########.#.#.#.###.#.###########.#.#.#.#.#######.#.#.#.###.#.#.#.#.#.#.#.#.#############.###.#######.#.#########.#####.#.#.######### +#...#.#...........#...#.....#.#...#...#...#.#...#.......#.#...#...#.#.#.#.#...#.#.#.....#.......#.#...#.......#.......#...#...#...#.........# +###.#.#.#####################.#.#.#.#.#.###.###########.#.#######.#.#.#.#.#####.#.#####.#.#####.#.#.###.#############.#.###.#.#############.# +###...#.........#.....#.....#...#...#...#...#####.......#.#.......#.#.#.#...#...#...###.#.#...#.#.#.....#.....#.......#.#...#...............# +###############.#.###.#.###.#############.#######.#######.#.#######.#.#.###.#.#####.###.#.#.#.#.#.#######.###.#.#######.#.################### +#...#.....#.....#.#...#.###...........#...#######...#...#.#...#...#.#.#...#.#.....#...#.#.#.#...#.........###.#.....#...#.....#.............# +#.#.#.###.#.#####.#.###.#############.#.###########.#.#.#.###.#.#.#.#.###.#.#####.###.#.#.#.#################.#####.#.#######.#.###########.# +#.#.#...#.#.......#.....#...#.........#.#########S..#.#.#.#...#.#.#.#.###.#.###...#...#...#.................#.#.....#.#.......#.#...........# +#.#.###.#.###############.#.#.#########.#############.#.#.#.###.#.#.#.###.#.###.###.#######################.#.#.#####.#.#######.#.########### +#.#.....#.#...#...###...#.#.#...#.......#########...#.#.#.#...#.#.#.#.#...#...#...#...#.....#...#...........#...#...#.#.#.......#...........# +#.#######.#.#.#.#.###.#.#.#.###.#.###############.#.#.#.#.###.#.#.#.#.#.#####.###.###.#.###.#.#.#.###############.#.#.#.#.#################.# +#...#...#...#...#.....#...#.#...#.###############.#.#.#...#...#.#.#.#.#...#...#...#...#...#...#.#.#.......#...###.#...#...#.......#.........# +###.#.#.###################.#.###.###############.#.#.#####.###.#.#.#.###.#.###.###.#####.#####.#.#.#####.#.#.###.#########.#####.#.######### +#...#.#.....#.............#.#...#.#############...#.#.#.....#...#...#...#.#...#...#...###.....#.#...#...#...#.....#.........#...#...#.......# +#.###.#####.#.###########.#.###.#.#############.###.#.#.#####.#########.#.###.###.###.#######.#.#####.#.###########.#########.#.#####.#####.# +#.....###...#.#...........#...#...#############...#.#.#.....#.....#.....#...#...#.#...#...#...#...#...#...........#...........#...###.#.....# +#########.###.#.#############.###################.#.#.#####.#####.#.#######.###.#.#.###.#.#.#####.#.#############.###############.###.#.##### +#...#...#...#.#.......#.....#.#E#####...###...###.#.#.#.....#.....#...#...#.#...#.#.###.#.#...#...#.............#.#...#...#...#...#...#.....# +#.#.#.#.###.#.#######.#.###.#.#.#####.#.###.#.###.#.#.#.#####.#######.#.#.#.#.###.#.###.#.###.#.###############.#.#.#.#.#.#.#.#.###.#######.# +#.#...#.###...###...#...###.#.#.......#...#.#.#...#.#.#.#...#.....#...#.#.#.#.#...#...#.#...#.#.................#...#.#.#...#...#...#.....#.# +#.#####.#########.#.#######.#.###########.#.#.#.###.#.#.#.#.#####.#.###.#.#.#.#.#####.#.###.#.#######################.#.#########.###.###.#.# +#.....#.#.........#.........#.............#.#.#.#...#.#.#.#.#...#.#.###.#.#.#.#.#.....#...#.#.......................#.#...........#...#...#.# +#####.#.#.#################################.#.#.#.###.#.#.#.#.#.#.#.###.#.#.#.#.#.#######.#.#######################.#.#############.###.###.# +#.....#...#.............#.......#...#...#...#.#.#...#.#.#.#.#.#.#.#.#...#.#.#.#.#...#...#.#.#.....#.....#...........#.#...#.....#...###.....# +#.#########.###########.#.#####.#.#.#.#.#.###.#.###.#.#.#.#.#.#.#.#.#.###.#.#.#.###.#.#.#.#.#.###.#.###.#.###########.#.#.#.###.#.########### +#.......#...#...........#.#.....#.#...#.#.#...#.#...#.#.#.#.#.#.#.#.#...#.#.#.#.#...#.#.#.#.#...#.#.#...#.........###.#.#.#...#.#.....#.....# +#######.#.###.###########.#.#####.#####.#.#.###.#.###.#.#.#.#.#.#.#.###.#.#.#.#.#.###.#.#.#.###.#.#.#.###########.###.#.#.###.#.#####.#.###.# +#...###...###.........#...#.....#.....#.#.#.#...#...#.#...#...#.#.#...#.#.#.#.#.#...#.#.#.#.#...#.#.#.....#.....#...#...#.#...#...#...#...#.# +#.#.#################.#.#######.#####.#.#.#.#.#####.#.#########.#.###.#.#.#.#.#.###.#.#.#.#.#.###.#.#####.#.###.###.#####.#.#####.#.#####.#.# +#.#.#...#.........###.#.#...###...#...#.#.#...#.....#.......#...#...#.#.#.#.#.#...#.#.#.#.#.#...#.#...#...#...#...#.....#...###...#.......#.# +#.#.#.#.#.#######.###.#.#.#.#####.#.###.#.#####.###########.#.#####.#.#.#.#.#.###.#.#.#.#.#.###.#.###.#.#####.###.#####.#######.###########.# +#.#...#...#.....#.....#...#...#...#...#...#.....#.....#.....#.#.....#.#.#...#.#...#.#.#.#.#...#.#...#.#...#...#...#.....###...#.....#.....#.# +#.#########.###.#############.#.#####.#####.#####.###.#.#####.#.#####.#.#####.#.###.#.#.#.###.#.###.#.###.#.###.###.#######.#.#####.#.###.#.# +#.#...#...#...#...#...#...#...#...#...#...#.......#...#.....#...#.....#.###...#...#.#.#.#...#.#.#...#...#.#.###...#.........#.....#.#...#.#.# +#.#.#.#.#.###.###.#.#.#.#.#.#####.#.###.#.#########.#######.#####.#####.###.#####.#.#.#.###.#.#.#.#####.#.#.#####.###############.#.###.#.#.# +#.#.#.#.#.....#...#.#.#.#.#...#...#.#...#.....#.....#.......#.....#...#...#.#.....#...#...#.#.#.#...#...#.#...###...#.......#...#.#.....#...# +#.#.#.#.#######.###.#.#.#.###.#.###.#.#######.#.#####.#######.#####.#.###.#.#.###########.#.#.#.###.#.###.###.#####.#.#####.#.#.#.########### +#.#.#.#.....#...#...#.#.#...#.#...#.#...#...#...#...#.....###.....#.#.#...#.#.#...........#.#.#.#...#...#.#...#.....#.....#.#.#.#...........# +#.#.#.#####.#.###.###.#.###.#.###.#.###.#.#.#####.#.#####.#######.#.#.#.###.#.#.###########.#.#.#.#####.#.#.###.#########.#.#.#.###########.# +#.#.#.#...#.#...#.#...#.###.#.#...#...#...#...#...#.#...#.....#...#.#...###...#...#...#...#.#...#.#...#.#.#.###...#...#...#...#...#...#.....# +#.#.#.#.#.#.###.#.#.###.###.#.#.#####.#######.#.###.#.#.#####.#.###.#############.#.#.#.#.#.#####.#.#.#.#.#.#####.#.#.#.#########.#.#.#.##### +#.#.#.#.#...###.#.#...#.#...#.#.#...#.#.......#.###...#.#.....#...#.....#...###...#.#...#.#.#.....#.#...#.#.....#...#.#.....#...#.#.#.#.....# +#.#.#.#.#######.#.###.#.#.###.#.#.#.#.#.#######.#######.#.#######.#####.#.#.###.###.#####.#.#.#####.#####.#####.#####.#####.#.#.#.#.#.#####.# +#.#.#.#.....#...#...#.#.#...#.#...#...#.......#.......#.#.....#...#...#...#...#...#.#.....#.#.#...#.....#...#...###...#...#...#.#.#.#.#...#.# +#.#.#.#####.#.#####.#.#.###.#.###############.#######.#.#####.#.###.#.#######.###.#.#.#####.#.#.#.#####.###.#.#####.###.#.#####.#.#.#.#.#.#.# +#.#.#.....#.#...#...#...###.#.###.............#...#...#...#...#.....#.#.....#.#...#.#.#...#.#.#.#.#...#...#...###...#...#...#...#.#.#.#.#.#.# +#.#.#####.#.###.#.#########.#.###.#############.#.#.#####.#.#########.#.###.#.#.###.#.#.#.#.#.#.#.#.#.###.#######.###.#####.#.###.#.#.#.#.#.# +#.#...#...#.#...#.#.........#...#.....#.....#...#.#.....#.#.....###...#...#...#.....#.#.#.#.#...#.#.#...#.......#.#...#...#.#...#.#.#...#.#.# +#.###.#.###.#.###.#.###########.#####.#.###.#.###.#####.#.#####.###.#####.###########.#.#.#.#####.#.###.#######.#.#.###.#.#.###.#.#.#####.#.# +#.#...#.....#...#.#...........#.#.....#.#...#.#...#...#.#.#...#...#.#...#...#...###...#.#...###...#...#...#.....#...###.#...#...#.#...#...#.# +#.#.###########.#.###########.#.#.#####.#.###.#.###.#.#.#.#.#.###.#.#.#.###.#.#.###.###.#######.#####.###.#.###########.#####.###.###.#.###.# +#.#.#.......###.#.###.........#.#.#...#.#.#...#...#.#.#.#.#.#.#...#.#.#.....#.#.#...#...#.......#...#.#...#...........#.....#.#...#...#.#...# +#.#.#.#####.###.#.###.#########.#.#.#.#.#.#.#####.#.#.#.#.#.#.#.###.#.#######.#.#.###.###.#######.#.#.#.#############.#####.#.#.###.###.#.### +#...#.#...#.....#.#...#...#...#.#.#.#.#.#.#.#...#.#.#.#.#.#.#.#...#.#.........#.#...#.###.....#...#.#.#...#...#...#...###...#.#.#...#...#...# +#####.#.#.#######.#.###.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.###########.###.#.#######.#.###.#.###.#.#.#.#.#.#####.###.#.#.###.#####.# +#.....#.#...#...#.#.#...#.#.#.#.#.#.#.#.#.#.#.#...#.#.#.#.#.#...#.#.#...#.....#.#...#...#.....#...#.#.#...#.#.#.#.#.....#...#.#.#...#.#...#.# +#.#####.###.#.#.#.#.#.###.#.#.#.#.#.#.#.#.#.#.#####.#.#.#.#.###.#.#.#.#.#.###.#.#.#####.#.#######.#.#.#.###.#.#.#.#####.###.#.#.###.#.#.#.#.# +#.......###...#...#...###...#...#...#...#...#.......#...#...###...#...#...###...#.......#.........#...#.....#...#.......###...#.....#...#...# +############################################################################################################################################# \ No newline at end of file diff --git a/output/20-1.txt b/output/20-1.txt new file mode 100644 index 0000000..e491804 --- /dev/null +++ b/output/20-1.txt @@ -0,0 +1 @@ +1441 \ No newline at end of file diff --git a/output/20-2.txt b/output/20-2.txt new file mode 100644 index 0000000..891bf92 --- /dev/null +++ b/output/20-2.txt @@ -0,0 +1 @@ +1021490 \ No newline at end of file diff --git a/src/main/scala/adventofcode/solutions/Day20.scala b/src/main/scala/adventofcode/solutions/Day20.scala new file mode 100644 index 0000000..2a2e3c5 --- /dev/null +++ b/src/main/scala/adventofcode/solutions/Day20.scala @@ -0,0 +1,55 @@ +package adventofcode.solutions + +import adventofcode.Definitions.* + +@main def Day20 = Day(20) { (input, part) => + + case class Vec(i: Int, j: Int): + infix def +(that: Vec): Vec = Vec(i + that.i, j + that.j) + + val (grid, start, end) = + val rawGrid = input.toLines.map(_.toIndexedSeq) + def find(c: Char): Vec = rawGrid.view.zipWithIndex.flatMap((row, i) => row.view.zipWithIndex.collect { case (`c`, j) => Vec(i, j) }).head + (rawGrid.map(_.map { + case '#' => false + case _ => true + }), find('S'), find('E')) + + val adjacent = + for + i <- -1 to 1 + j <- -1 to 1 + if i.abs + j.abs == 1 + yield Vec(i, j) + + def inBounds(p: Vec): Boolean = grid.indices.contains(p.i) && grid(p.i).indices.contains(p.j) + def walkable(p: Vec): Boolean = grid(p.i)(p.j) + + def bfs(current: Set[Vec], history: Map[Vec, Int], steps: Int): Map[Vec, Int] = + val nextHistory = history ++ current.map(_ -> steps) + if current.contains(end) then + nextHistory + else + val nextCurrent = current.flatMap(p => adjacent.map(p + _)).filter(inBounds).filter(walkable).diff(history.keySet) + bfs(nextCurrent, nextHistory, steps + 1) + + val distances = bfs(Set(start), Map.empty, 0) + val distancesSeq = distances.toSeq + + def around(positions: Set[Vec], history: Map[Vec, Int], distance: Int, duration: Int): Map[Vec, Int] = + val nextHistory = history ++ positions.diff(history.keySet).map(_ -> distance).toMap + if distance < duration then + val nextPositions = positions.diff(history.keySet).flatMap(p => adjacent.map(p + _)) + around(nextPositions, nextHistory, distance + 1, duration) + else + nextHistory + + def count100(duration: Int): Int = + val arounds = around(Set(Vec(0, 0)), Map.empty, 0, duration).toSeq + distancesSeq.map((p, d) => arounds.view.map((q, e) => (q + p, e)).count((q, e) => inBounds(q) && walkable(q) && distances(q) - d - e >= 100)).sum + + part(1) = count100(2) + + part(2) = count100(20) + +}