From a0ab89faf725d10ff4b46fa9a425a80a52304ab7 Mon Sep 17 00:00:00 2001 From: smabuk <2011834+smabuk@users.noreply.github.com> Date: Mon, 16 Dec 2024 06:15:45 +0000 Subject: [PATCH] 2024 Day16 Part1 Solved --- Data/2024_16.txt | 141 ++++++++++++++++++++++++++++++++++++++++ Solutions/2024/Day16.cs | 110 +++++++++++++++++++++++++++++++ Tests/2024/Tests_16.cs | 62 ++++++++++++++++++ 3 files changed, 313 insertions(+) create mode 100644 Data/2024_16.txt create mode 100644 Solutions/2024/Day16.cs create mode 100644 Tests/2024/Tests_16.cs diff --git a/Data/2024_16.txt b/Data/2024_16.txt new file mode 100644 index 0000000..0857ab2 --- /dev/null +++ b/Data/2024_16.txt @@ -0,0 +1,141 @@ +############################################################################################################################################# +#.#.................#...........#.........#.....#.......#.......#.......#.........#.....#...#.................#.........#.......#..........E# +#.#.###.###.#######.###.#####.###.#####.#.###.#.###.#.#.#.#.###.#.#####.#.#####.#.#.#.#.#.#.#.#########.#.#.#.#.###.###.#.###.#.###.###.#.### +#...#.#.....#...#.......#...#.#...#.....#.....#.#...#.#...#...#.#.....#.#...#...#...#.#...#.#...#.......#.#.#.#...#.#...#.#...#...#.....#...# +#.###.#.#.###.#.#########.#.###.###.###########.#.#.#.#######.#.#####.#####.#.#.#####.#####.#####.###.#.###.#.#####.#.###.#.#####.#.###.###.# +#.#...#.......#...........#...#...#...#.#.........#.......#...#.....#.......#.#.....#.#.#...#.....#...#...#.#.......#.......................# +#.###.#######################.###.###.#.#.###.#######.###.#.#######.#########.#####.#.#.#.###.#####.#.###.#.#########.#########.###.######### +#.....#...............#.#.....#.#.#.#.#.....#...#...#.......#...#.......#...#.....#...#.....................#.......#...........#.....#.....# +#####.#######.#######.#.#.###.#.#.#.#.#######.#.#.#.#.#######.#.#######.#.#.#####.#############.#.###.###.#.###.###.#.###########.#.#.#.###.# +#...#.........#.....#.#.#.#.....#.#.#.........#.........................#.#.....#.#...#...#.....#.#.#.....#...#...#...#.......#...#.#...#.#.# +###.#############.###.#.#.#######.#.###.###.#.#.#.#.#.#.#.#######.#.#.###.#####.#.#.#.#.#.#####.#.#.#.#######.###.#.###.#####.#.###.#####.#.# +#...#...#.........#...#.#.......#...#...........................#.#.#.#...#.......#.#...#...#...#.....#.......#...#.#.#.#...#...............# +#.#.#.###.#####.###.###.#######.###.#.#######.#.#.#.#.###.###.#.#.#.#.#.###.#######.#######.#.#######.#.#######.###.#.#.#.#.#####.#.#.#.#.#.# +#.#...#...#...#...................#.#.#.......#.#.#.#.........#.#.#...#.#.#...#...#.#.#...#.#.#.......#...............#.#.#.......#...#...#.# +#.###.#.#####.#######.#.#.#.#.#.###.#.#.#####.#.#.#.#.###########.#.###.#.#.###.#.#.#.#.#.#.#.#.#######.###########.###.#.#########.#####.#.# +#.#.#.#.....#.....#.....#.#...#.....#.#.......#...#.#.#.#.........#...#.#...#...#...#.#.#...#.#.#.......#...#...........#.....#.....#.#...#.# +#.#.#.#####.#.###.#####.#.###########.#######.#####.#.#.#.###########.#.#####.#######.#.#####.#.#.###.###.#.#.#################.#####.#.###.# +#.#.......#.#...#.....#.#...........#.#.......#...#...#.#...#...........#...#.........#.#...#...#.#...#...#.#...#.............#...#.#...#...# +#.#########.#.#.#####.#.###########.#.#.#######.#.#.###.###.#.###########.#.#######.#.#.#.###.#####.###.###.###.#.#.#########.###.#.#.###.### +#...........#.#.....#.#.#...........#.......#...#.#.....#...#.#...........#...#.....#...#.#...#...#.#...#.#...#.#.#...#.#.........#.....#...# +#.###########.#####.#.###.#####.#############.###.#######.#####.#############.#.#####.###.#.###.#.#.#.###.###.#.#####.#.#.#########.#######.# +#...#.......#.#.#...#...#.#...#.#...........#.#.#.#.....#.#...#.#.........#...#.#...#...#.#...#.#.#.#.......#.............#...#...#.#.....#.# +###.#.###.###.#.#.#####.#.#.#.###.#########.#.#.#.#.#.#.#.#.#.#.#.###.###.#.###.#.#.###.#.###.#.#.#.#.#########.#####.###.#.#.#.#.#.#.###.#.# +#.#.#...#.......#.....#.#...#...#...#.#.....#.#...#.#.....#.#...#...#.#...#.....#.#...#.#...#...#.#...#.......#.#.....#...#.#.#.#...#...#.#.# +#.#.###.###########.#.#.#######.###.#.#.#####.#.###.#.#####.#######.#.#############.###.#.#######.###.#.#####.###.###.#.#.#.#.#########.#.#.# +#.#...#...#.#.......#.......#.....#.#.........#.....#...#...#...#...#.......#.......#...#...#...#...#.#.#.......#.#.....#...#.....#.....#...# +#.###.###.#.#.#############.#.#####.#.#################.#.###.#.#.#########.#.#.###.#.###.#.#.#.###.###.#######.#.#.#############.#.######### +#...#.#.#...#.........#.....#.#...#.......#.......#...#.#.....#.#.#...#...#...#.#...#.#...#...#...#...#.#.....#...#...#...#.......#.........# +#.###.#.###.#########.###.###.#.#.#######.#.#####.#.#.#.#####.#.###.#.#.#.#####.#####.#.#####.#.#####.#.#.###.#######.#.#.#.#######.#######.# +#...#.#.#...#.....#.#...#.#...#.#.#.....#.#.....#...#...#...#.#...#.#...#.....#.....#.#.......#.........#...#.#...#.....#.#...#...#.#.....#.# +###.#.#.#.#.#.###.#.###.#.#.#.#.#.#.###.#.#####.#########.#.#####.#.#.#######.#.###.#.#####.#####.#########.#.#.#.#.#####.###.###.#.###.#.#.# +#...#.#...#.....#.....#.#.....#.#...#.....#.......#...#...#.......#.#.#...#.#.#...#.....#...#...#...#.....#.#...#...#...#.#.#...#.......#.#.# +#.#.#.#.###.###.#.#.###.#####.#.###########.#######.#.#.###########.#.#.#.#.#.#####.###.#####.#.#####.###.#.#########.###.#.###.#########.#.# +#.#...#.#.....#.#...#...#...#.#.........#.#.#...#...#...#...........#...#.#...........#.......#.......#.#.#...#...#...........#.#.....#...#.# +#.#.###.#.#.#.#.#.#.#.#.#.#.###########.#.#.###.#.#######.#####.###.#.###.#######.#####################.#.###.###.#.#######.###.#.###.#.###.# +#...............#.#.#.....#.........#...#.......#...#...#.#...#...#.....#.......#.#.........#.#.........#.#...#...#...#.#.....#.#...........# +#.#.#.###.#.#####.#.#.###.#####.#####.#.#####.#.###.#.#.###.#.#########.#######.###.#####.#.#.#.#.#.###.#.#.###.#####.#.#.###.#.###.#.#####.# +#.#.......#.......#.#...#.....#...#...#.#...#.....#...#.....#.........#.......#.........#.#.#.#.#.#...#.#.#.#...#...#.#.....#...#...#.#.....# +#.#.#######.#######.###.#.#.#####.#.#####.#.#####.###################.#.#######.#########.#.#.#.#.###.###.#.#.###.#.#.#####.#####.###.#.##### +#.#.......#.#.....#...#...#.#...#.#.#...#.#.#.#...#.......#.........#.#.#.....#.#...#...#.#...#.#...#...#...#.#...#.#.....#.......#.....#...# +#.#.#####.#.#.###.###.###.###.#.#.#.#.#.#.#.#.#.###.###.#.#######.###.#.#.###.###.#.#.#.#.###.#.#.#.###.#####.#.###.#####.###.###########.#.# +#...#...#...#.......#...#.#...#...#...#...#.#.#.#.#.#...#.......#.#...#.#.#.#.....#...#.#...#.#...#...#...#.....#.#...#...#...#...........#.# +###.#.#####.#.###.#.###.#.#.#####.#########.#.#.#.#.#.#.#######.#.#.#####.#.#####.#####.#.#.###.#####.###.#.#####.###.#.#####.#.###.#####.#.# +#...#.......#.#...#.#.....#.#...#.#.....#...#...#...#.#.#.....#...#.....#.........#...#.#.#...............#.#...#.#...#.....#.#.#.......#...# +#.#.#####.#.###.#####.#####.#.#.#.#####.#.###.###.#.#.###.###.#####.###.#.#########.#.#.#.#############.#.#.#.#.#.#.#######.###.#####.#.#.### +#.#...#...#.....#...#...#...#.#.......#.#.#.#.#.....#...#.#.......#.#.#.#.#.....#...#.#.#...#.......#...#.#...#...#.#.........#...#...#.#...# +#.#.#.#.#.#.#.###.#.###.#.#.#########.#.#.#.#.#.#####.#.#.#######.#.#.#.#.#.#.#.#.###.#.#####.#####.#.#########.###.#.###.###.###.#.#####.#.# +#.......#.....#...#.........#.....#.#.#.#.#.#.#.....#...#...#...#.#.#.#.#.....#.....#.#.......#.#...#...........#.......#...#.....#.........# +#.#######.#####.#########.###.###.#.#.#.#.#.#.#.###.#.#.###.#.#.#.#.#.#.#.###.#######.#########.#.#######.#.#####.#.###.###.#######.#####.### +#...#...#.....#.......#.......#.#.#.#...#.#.#.#.....#.#...#.#.#...#...#...#.#.#.#.....#...#.....#.........#.#...#.#...#.#.#.......#.....#...# +#.#.#.#.###.#######.###.#######.#.#.#.###.#.#.#.###.#.###.#.#.###.###.###.#.#.#.#.#######.#.#.#####.#####.#.###.#.#####.#.###.###.#####.#.#.# +#.#...#...#.#.....#.#...#.......#.#.#.#...#.#...#.#.#...#.#.....#.#.#...#.#.....#.......#...#...........#.#.....#...........#.#.#.#.#...#.#.# +#.#######.#.#.###.#.#.###.###.###.#.#.#.###.#####.#.###.#.#####.#.#.###.#.#####.#######.#.#########.#####.#####.#############.#.#.#.#.#.#.#.# +#.....#.....#.#.#...#...#.#.#.......#.#.#.........#.....#.#.....#.#...#.#...#.#...#...#.#.......#.#...#...#.....#.........#...#.#...#...#.#.# +#####.#.###.#.#.#######.#.#.#.#.###.#.#.###.#.###########.#.#####.#.#.#.###.#.###.#.#.#.#######.#.###.#.###.###.#.#####.#.#.###.#.#.###.#.### +#...#.#.#...#.#.....#.#.#.#.#.#.#.....#...#.#.........#...#...#...#.#...#...#...#...#.#...#...#.....#.#.....#.....#.....#.#.#...#...#...#...# +#.#.#.#.#####.#.###.#.#.#.#.#.#.#######.#.#####.###.###.#####.#.#########.###.#####.#.###.###.#####.#.#.#######.###.###.#.#.###.#.###.###.#.# +#.#.#.#.....#.#.#.......#.#...#.#.......#.....#.#.#.........#.#...#.......#.#...#...#.#...#...#.....#...#.........#...#.......#...#...#.....# +#.###.#####.#.#.#######.#.#####.#.###.#.#####.#.#.#.#.###.###.###.#.#######.#.#.#.#.#.#.###.###.#########.#######.###.#.#####.#.#.#.#####.#.# +#.......#...#.#.....#...#...#...#.#.#.#.#...#.#.#.#.....#.#...#.....#.....#.#.#...#...#.#...#...#...#.....#.....#.#...#.....#.#.#...#.....#.# +#.#######.#.#.#.###.#.#####.#.###.#.#.#.#.###.#.#.#.###.###.###.###.#.###.#.#.#########.###.#.###.#.#.#########.#.#.#.#####.#.#.#.###.#####.# +#...#.....#.#.#...#.#.....#.......#.#.#.#.#.......#...#...#...#.#...#.#.....#.....#...#...#.#.#...#.#.....#.....#...#...#...#.#.#.#.......#.# +###.#.#####.#.###.#.#####.###.###.#.#.#.#.#.#########.###.###.###.#.#.#.#########.#.#.###.#.#.#####.#####.#.###.#######.###.#.###.#.#####.### +#...........#...#.#.....#...#.#...#.#.#...#.................#.#...#.#.#.#.........#.#...#.#.#.#.......#...#...#.......#...#...#...#.#...#...# +#.#####.#.#.###.#.###.#.###.###.#.#.#.###.#######.#.###.###.#.#.###.#.###.#########.###.#.#.#.#.#####.#.###.#.#######.###.#####.###.#.#####.# +#...#...#.....#.#.....#...#...#.#...#.#...#.......#...#.#.#.#...#...#...#.#...#.....#.#...#.....#.....#...#.#.#.........#...#...#.#.#.....#.# +###.#.#####.###.#####.#.#####.#.#.#.#.#####.#########.#.#.#.#####.#.###.#.###.#.#####.#.#######.#####.###.###.#########.###.#.###.#.#.#.#.#.# +#.#.....#.#.#...#...#.#.....#...#.#.#.......#.....#...#.#.#.......#...#.....#.#.........#...#...#...#...#...#.........#...#.............#.#.# +#.#.###.#.#.#.#.#.#.#######.#####.#.#.#######.#.###.###.#.#######.###.#####.#.#.#.###.###.#.#####.#.#.#####.#########.###.#####.#.#####.###.# +#.....#.#...#.#...#.......#.#.....#...#...#...#.......#...#.#...#...#...#.#.#.#.#.#.......#.#.....#.#.#.....#.........#.......#.#...#...#...# +#.#####.#.#.#.###.#######.#.#.#########.#.#####.#.#.#####.#.#.#.#.#.###.#.#.#.#.###.#######.#.###.#.###.#.#.#.#.###.###.###.#.#.###.#.###.#.# +#.#.....#.#.......#.....#.#.#.........#.#.#...#...#.......#.#.#.#.#.#.#.#...#.#.....#.........#...#.....#...#.........#...#...#...#.#.#...#.# +#.#.#######.#######.###.#.#.#########.#.#.#.#.#####.###.###.#.#.#.#.#.###.###.###########.#####.#########.#.#####.#.#.#.###.###.#.#.#.#.##### +#.#.#...#.....#.....#.#.#.........#...#.#...#.#...#.........#.#...#...#...#...#.......#...#...........#...#.#...#.#...#...#...#.#.....#.#...# +###.#.#.#.#####.#####.#.###########.###.#####.#.#.#########.#.#.#######.###.###.#.###.#.#.#.#######.#.#.###.#.#.#.#.#####.###.#####.###.#.#.# +#...#.#...#.....#.....#.#...........#...#.#...#.#.........#.#.#.#...#...#...#...#...#...#.#.....#...#.#...#...#.#.#.#.......#...#.....#...#.# +#.###.#####.#####.#.#.#.#.#######.###.###.#.###.###.#######.#.###.#.#.###.###.#####.#####.###.###.#.#####.#####.###.#.#.###.###.#.#.#.#####.# +#.....#...#.#.#...#.#.#.#.....#...#...#...#.....#.#.........#.#...#.#...#.....#...#...#...#...#...#.#...#.....#.....#.#.#.....#...#.#.#...#.# +#.#######.#.#.#.#.#.#.#.###.#.#.###.#####.#######.###########.#.###.###.#.#####.#.#.#.#.###.#.#.#####.#.###.#.#######.#.###########.#.#.#.#.# +#...#.....#.#.....#.#.#...#.#.#...#.#.......#...#.......#...#...#.#.....#.#.....#.#.#.#.#...#...#...#.#.#.....#.....#.#.#...........#.#.#.#.# +###.#.#####.#######.#.###.###.###.#.#.#####.#.#.###.###.#.#.#####.#########.#####.###.#.#.#.#####.#.#.#.#.#.###.#.###.#.#.###.#####.#.#.#.#.# +#...#.#...#...#...#.#.......#.....#...#...#...#.....#...#.#...#.#...............#.....#.#.#.....#.#.#.#...#.#...#.#...#.#.#...#...#.#...#...# +#.###.#.#.###.#.#.#.#.#.###.#.#.#.#####.#.###########.###.###.#.#.#.#.###.#.#.#.#######.#.#####.#.#.#.#.#####.###.#.###.#.#.###.#.#.#####.#.# +#.....#.#...#...#.#...#.....#.#.#...#...#.......#...#...#.....#...#.....#...#.#.#.....#.#.#.......#.#...#.....#.#.#.#.#...#.#...#.#.#.....#.# +#####.#.###.###.#.#.#####.#####.###.#.#####.#####.#.###.#.#.###.#######.#####.#.###.#.#.###.#.#.###.###.#.#####.#.#.#.#####.#.#.#.#.#.#.#.#.# +#.#...#.....#.....#.....#.......#...#.#...#.......#.....#.#.#.........#.......#...#.#.....#.#.#...#...#...#.....#...#...#.....#.#.#...#.#...# +#.#.#####.#.#.#########.###.#.#######.#.#.#########.#.###.#.#############.#######.#######.#.#.#####.#.#####.#########.#.#.###.#.###.###.#.### +#.........#...#...#...#...#.#.#.......#.#.......#.....#...#.............#.....#...#.....#...#.......#.#.......#.......#.#...#.#...#.......#.# +#.#####.#######.#.###.###.#.###.#########.#.###.#.#####.###############.#######.###.###.#############.#.#####.#.#####.#.###.#.#.#.#.#####.#.# +#.#.#...#.......#...#.....#...#.........#.#.#...#.....#...#.#.........#.#.....#.....#...#.............#.....#...#...#.#...#...#.#.....#.#.#.# +#.#.#.#.#.#########.#####.###.#########.###.#.###.###.#.#.#.#.#######.#.#.###.#######.###.###############.#.#####.#.#.###.###.#.###.#.#.#.#.# +#...#.#.#.#...#...#.....#.#...#.......#.#...#.....#...#.#.#.....#.#...#...#...#.......#...#...............#.#...#.#.#...#...#.......#.#.#.#.# +###.#.#.#.#.###.#.#####.#.#.#.#.#.#####.#.###.###.#.###.#.#####.#.#.#######.###.#######.###.#.###########.###.#.#.#.#.#.#######.#.#.#.#.#.#.# +#...#.#.#.#.....#.....#.#...#.#.#.#.....#.#.....#.#.....#...#...#.#.#.....#.#...#.....#...#.#.#.........#...#.#...#.#.#.#.........#.#...#.#.# +#.###.#.#.#######.###.#.###.###.#.#.#####.#####.###.#####.#.#.###.#.#.###.#.#.###.###.###.###.#.###.###.###.#.#####.###.#.#####.###.###.#.#.# +#...#.#.#.#...#...#...#...#.#...#...#...#...#.....#.#.......#.#...#...#.#...#.......#.#.#.....#...#.....#...#.#...#...#.#.#...#.#...#.#.#.#.# +#####.#.#.#.#.#.#########.#.#.#########.#.#.#####.###.#######.#.#######.#######.#####.#.#####.#######.#.#.###.#.#####.#.#.#.#.#.#.###.#.#.#.# +#.....#...........#...#...#.#...#.......#.#.....#.....#.......................#.#.....#...#...#.....#.#...#...#.....#...#.#.#.....#...#.#...# +#.###.#.#####.#.#.#.#.#.###.###.#####.###.#####.###.###.###########.#####.###.###.#####.###.###.###.#.#####.###.#.#.###.#.#.###.###.###.#.#.# +#.....#...#.#.#.#.#.#...#.#.#.#.#...#.#...#...#.#.....#...........#...#.#.#.#.....#.....#...#.#.#.#.#.....#.#...#.#.......#.#...............# +#.###.###.#.#.###.#.#####.#.#.#.#.#.#.#.#####.#.#.###############.###.#.#.#.###########.#.###.#.#.#.#####.#.#.#.###.#####.###.#.#.###.#.#.#.# +#...#.#.#...#.......#.....#...#.#.#.#.....#...#.#...#...........#.#.....#.#.............#.#...#.#.#.#.....#.#.#...#...#.#.......#.#...#.#...# +#.###.#.###.#####.#.#####.###.#.#.#.#####.#.###.#.#.#.#####.#####.#.#####.#.#.#####.#####.###.#.#.#.#.#####.#.###.###.#.#########.#.###.#.#.# +#.#...#...#...#...#.....#.#...#...#...#...#...#...#.#.#...#...#...#...#...#.#.......#.....#...#.#...#.......#.....#.........................# +###.#.#.#.###.#.#######.#.#.###.#####.###.###.###.#.#.#.#.###.#.###.###.###.#####.#.#.#####.#.#.###.#######.###.#.###########.###.#########.# +#...#...#.#...#...#...#.#.#...#.....#...#...#...#.#.....#.#.#.#.#...#...#.#...#.#.#.#...#...#.#...#.#.........#.#...........#...#.#.....#...# +#.###.#.###.#####.#.#.#.#.###.#.#.#.###.###.#.###.#######.#.#.#.#####.###.###.#.#.###.#.#.#######.#.#########.#.#########.#.#.#.###.###.#.#.# +#.....#.....#.....#.#...#.#...#.#.#.#...#.#.#.#...#...#.....#.#...#...#.....#...#.......#...#.....#.......#...#.#...........#.#.#...#...#...# +#.###.#.#####.#####.#####.#.###.#.#.#.###.#.#.#.###.#.#####.#.###.#.###.#######.###########.#.#.#########.#.###.###.###########.#.###.#####.# +#.......#.....#.#...#.......#...#.#.#...#...#.......#...#...#...#...#.........#.....#.....#.#.#.#.....#...#...#...#...#.....#...#...#.....#.# +#.#.#.###.#####.#.#.#.###########.#.###.#.###.#########.#######.#####.#######.###.#.#.#.#.#.#.###.###.###.#####.#.###.#.###.#.#.#.#.###.#.#.# +#...#...#.......#...#...........#.#...#.#.........#...#.......#.....#.......#...#.#...#.#.#.#.......#...#.....#.#.#...#...#...#.#.#.#.#.#.#.# +#.###.#.###.#######.###########.#.#####.#.#########.#.###.###.#.#.#.#######.###.#.###.#.#.#.#.#########.#####.###.#.#####.#####.#.#.#.#.###.# +#.#.......#.#.......#.....#.......#.....#.#.....#...#...#...#.#.#.#.........#...#...#.#.#.....#.........#...#.#.....#.....#...#.#.#...#.....# +#.#.#.#####.#.#######.###.#######.#.#######.#.#.#.#####.#####.#.#.###########.###.#.###.#####.#.#########.###.#.###.#.#####.#.#.#.###.#.###.# +#.#.....#...#...#...#.#.#.#...#...#...#.....#.....#...#.......#...#.........#.#...#.....#...#.#...#...#.......#.#.#.#.#.....#.#.#...#...#...# +#.#####.#.#####.#.#.#.#.#.#.#.#.#####.#.#############.#.#######.#####.#######.#.#.#########.#.#.#.#.###.#######.#.#.#.###.#####.#.#.#.#.###.# +#...#.#.#.#...#...#.#...#...#.#.#...#.#.#.......#...#.....#.#...#...#...#.....#.#...#.....#.#.#.#.#.............#...#...#.#...#.#.....#.....# +###.#.#.#.#.#.#####.###.#####.###.#.#.#.#.#.###.#.#.#.###.#.#.###.#.###.#.#####.#.#.###.#.#.#.#.#.#######.#####.###.###.#.#.#.#.#.###.#####.# +#.#...#.#...#.....#...#.#...#.#...#.#.#.#.#.....#.#.#.#.....#.....#.....#.......#.#.....#.#.#...#.....#.#.....#...#.....#...#.#.#...#...#...# +#.###.#.#####.#####.###.#.#.#.#.###.#.#.#.#.#####.#.#.###.###.#.###.###.#########.#######.#.###.###.#.#.#####.###.#######.###.#.#.#.#.#.#.### +#...#.#.......#...#.....#.#.#.#...#.#.#...#.#.....#.#...#.#.....#.......#.........#.....#.....#.#...#.#.....#...#...#.....#.#...#.....#.#.#.# +#.#.#.#########.#.#.###.#.#.#.#.###.#.#.###.#.#####.#.#.###.#.###.#######.#######.#.###.#######.#.#.#.#.###.###.#.#.#.#####.#####.###.#.#.#.# +#.#...#.#.......#.....#.#.#.#...#...#.#.....#.#.....#.......#.....#.....#.#.......#.#.#.......#.#.#.#.#...#...#.#.#.#...#.............#.#.#.# +#.#####.#.###.#####.#.###.#.###.#.###.#.#####.#.###############.###.###.#.#.#######.#.#######.#.#.#.#.###.#.#.#.#.#.###.###.#.###.###.#.#.#.# +#.#.....#...#.#...#.......#...#.#...#.#.#.#...#.#...............#...#.#...#.#.......#.......#...#...#...#.#.#.#.#.#.#...#...#.#.....#...#...# +#.#.#.#.###.###.#.#.#########.#####.#.#.#.#.#.#.###.#########.###.###.#.#####.###.#.#####.#.#####.#####.#.#.###.###.#.###.#####.###.#####.#.# +#.#.#.#.#.#.....#...#.....#...#.....#...#...#.#.....#.............#.#...#.....#.#.#.......#.#.........#.#.#.........#.....#.......#.#.......# +#.#.#.#.#.#######.#.#.###.#.###.###.#.###.###.#######.#############.#.###.#.###.#.#.###.###.#######.#.#.#################.#.#.#####.#.###.### +#.#.#.#...#.......#...#.#.#.....#...#...#.#.#.#.........#.....#.....#.#.#.......#...#.....#.......#.#.#...#.............#.#...#.#...#.#.....# +#.###.###.#####.#.#.###.#.#######.#.#.#.#.#.#.#.#########.###.###.###.#.###.###.###.#.#.#.#######.###.###.#.###########.#####.#.#.#.#.###.#.# +#.....#...#...#.#.#.....#.#.....#.#.....#.........................#...#.#.....#.#.#...#.#.......#...#.#...#.....#...#.#.....#...#.#.#.#...#.# +#######.###.#.###.#.###.#.#.###.#.#.#######.#.#.#.###.#.###.###.#.#.###.#.#.###.#.#####.#####.#.###.#.#.#######.#.#.#.#####.###.#.###.#.#.#.# +#...............#.....#.#.#.....#...#.....#.#.#.#.#.#...#.....#.#.......#.#...#...#.....#...#.#...#...#.....#...#.#.......#.....#.....#.#...# +#.###.#########.#.#.###.#.###.#.###.#.#.###.#.#.#.#.#######.#.#.#######.#.#.#.###.#.###.#.#.#.#######.###.###.###.#######.#############.#.#.# +#...#...#.......#...#...#...#.#...............#.#.........#.#.#.....#...#...#...#.#...#...#...#.....#.#.................#.....#.......#.....# +###.#####.#######.#.#.#.###.###.###.#.#######.###########.#.#######.#.#.###.#.###.###.#.#####.#.###.#.#.###.###.###.#.#######.#.#####.#.#.#.# +#...#...#...#.....#...#.#.#...#...#.#...#...#.#.....#...#.#.......#...#.#...#.#...#...#...#...#.#.#.#.#.....#...#...#.#.....#...#...#.#.#...# +#.###.#.###.#.###.#.###.#.###.#.#.#.###.###.#.#.###.#.#.#.#######.#####.#.#.#.#.###.#.###.#####.#.#.#.#####.#.#.#.#####.###.#####.#.#.###.#.# +#S....#.......#.............#...#...........#.....#...#...............#.....#.......#...#.........#.............#.........#.......#.......#.# +############################################################################################################################################# diff --git a/Solutions/2024/Day16.cs b/Solutions/2024/Day16.cs new file mode 100644 index 0000000..35798fa --- /dev/null +++ b/Solutions/2024/Day16.cs @@ -0,0 +1,110 @@ +using static Smab.Helpers.Direction; + +namespace AdventOfCode.Solutions._2024; + +/// +/// Day 16: Reindeer Maze +/// https://adventofcode.com/2024/day/16 +/// +[Description("Reindeer Maze")] +public static partial class Day16 { + private const char START = 'S'; + private const char END = 'E'; + private const char WALL = '#'; + + private static char[,] _maze = default!; + private static Action? _visualise = null; + + [Init] + public static void LoadMaze(string[] input, Action? visualise = null) + { + _maze = input.To2dArray(); + + _visualise = visualise; + _maze.VisualiseMaze("Initial state:"); + } + + public static int Part1(string[] _, params object[]? args) + { + ReindeerPosition reindeerPosition = new(_maze.ForEachCell().Single(c => c.Value is START).Index, East); + Point end = _maze.ForEachCell().Single(c => c.Value is END).Index; + + (int lowestScore, List route) = _maze.FindShortestPath(reindeerPosition, end); + + _maze.VisualiseMaze($"Lowest Score {lowestScore}:", route); + + return lowestScore; + } + + public static string Part2(string[] input, params object[]? args) => NO_SOLUTION_WRITTEN_MESSAGE; + + private static (int, List) FindShortestPath(this char[,] maze, ReindeerPosition start, Point end) + { + int noOfRows = maze.RowsCount(); + int noOfCols = maze.ColsCount(); + + int[,] distances = new int[noOfCols, noOfRows]; + Point[,] previous = new Point[noOfCols, noOfRows]; + distances.FillInPlace(int.MaxValue); + previous.FillInPlace(new Point(-1, -1)); + + distances[start.Position.X, start.Position.Y] = 0; + SortedSet<(int, Point, Direction)> pq = []; + _ = pq.Add((0, start.Position, start.Direction)); + + while (pq.Count > 0) { + (int currentDist, Point position, Direction prevDir) = pq.Min; + _ = pq.Remove(pq.Min); + + if (position.Equals(end)) { + List path = []; + for (Point at = end; at.X != -1 && at.Y != -1; at = previous[at.X, at.Y]) { + path.Add(at); + } + + path.Reverse(); + return (currentDist, path); + } + + foreach (Direction direction in Directions.NESW) { + Point newPosition = position + direction.Delta(); + + if (maze.TryGetValue(newPosition, out char value) && value is not WALL) { + int turnCost = (prevDir != direction) ? 1000 : 0; + int newDist = currentDist + 1 + turnCost; + if (newDist < distances[newPosition.X, newPosition.Y]) { + _ = pq.Remove((distances[newPosition.X, newPosition.Y], newPosition, direction)); + distances[newPosition.X, newPosition.Y] = newDist; + previous[newPosition.X, newPosition.Y] = position; + _ = pq.Add((newDist, newPosition, direction)); + } + } + } + } + + return (-1, []); // Path not found + } + + + private record ReindeerPosition(Point Position, Direction Direction); + private record Step(ReindeerPosition Position, Direction PreviousDirection) + { + public int Score => Position.Direction != PreviousDirection ? 1001 : 1; + } + + private static void VisualiseMaze(this char[,] map, string title, IEnumerable? route = null, bool clearScreen = false) + { + if (_visualise is null) { + return; + } + + char[,] outputMap = (char[,])map.Clone(); + + foreach (Point point in route ?? []) { + outputMap[point.X, point.Y] = 'x'; + } + + string[] output = ["", title, .. outputMap.AsStrings()]; + _visualise?.Invoke(output, clearScreen); + } +} diff --git a/Tests/2024/Tests_16.cs b/Tests/2024/Tests_16.cs new file mode 100644 index 0000000..c27b697 --- /dev/null +++ b/Tests/2024/Tests_16.cs @@ -0,0 +1,62 @@ +namespace AdventOfCode.Tests.Year2024; + +public class Tests_16_Reindeer_Maze(ITestOutputHelper testOutputHelper) +{ + const int DAY = 16; + + [Theory] + [InlineData(""" + ############### + #.......#....E# + #.#.###.#.###.# + #.....#.#...#.# + #.###.#####.#.# + #.#.#.......#.# + #.#.#####.###.# + #...........#.# + ###.#.#####.#.# + #...#.....#.#.# + #.#.#.###.#.#.# + #.....#...#.#.# + #.###.#.#.#.#.# + #S..#.....#...# + ############### + """, 7036)] + [InlineData(""" + ################# + #...#...#...#..E# + #.#.#.#.#.#.#.#.# + #.#.#.#...#...#.# + #.#.#.#.###.#.#.# + #...#.#.#.....#.# + #.#.#.#.#.#####.# + #.#...#.#.#.....# + #.#.#####.#.###.# + #.#.#.......#...# + #.#.###.#####.### + #.#.#...#.....#.# + #.#.#.#####.###.# + #.#.#.........#.# + #.#.#.#########.# + #S#.............# + ################# + """, 11048)] + public async Task Part1(string input, int expected) + { + _ = int.TryParse(SolutionRouter.SolveProblem(YEAR, DAY, PART1, input, new Action(Callback)), out int actual); + actual.ShouldBe(expected); + await Task.Delay(200); // Allow time to visualise + } + + + + private void Callback(string[] lines, bool _) + { + if (lines is null or []) { + return; + } + + testOutputHelper.WriteLine(string.Join(Environment.NewLine, lines)); + } + +}