From a1b07a92d38a90c940d65a294b4922571eb80db9 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Sat, 23 Dec 2023 00:39:41 -0600 Subject: [PATCH] 2023-23 --- inputs/2023/23.txt | 141 ++++++++++++++++++++++++++++++++++++++ solutions/solutions.cabal | 7 +- solutions/src/2023/23.hs | 109 +++++++++++++++++++++++++++++ 3 files changed, 256 insertions(+), 1 deletion(-) create mode 100644 inputs/2023/23.txt create mode 100644 solutions/src/2023/23.hs diff --git a/inputs/2023/23.txt b/inputs/2023/23.txt new file mode 100644 index 0000000..438de80 --- /dev/null +++ b/inputs/2023/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#.###.#####.###.#.#.###.#.#.#######.# +#.#.#.......#...###...#...#.#.#...#...#.#.#.#.#.#.#.#.###.#.#.#.#.#.#...#.#.#...#.#...#.......#.#...#.>.>.###...#...###.#.#...#.#.#.#.......# +#.#.#######.#.#.#####.#####.#.#.#####.#.#.#.#.#.#.#.#.###.#.#.#.#.#.###.#.#.#.###.#.###.#######.###.#.#########.#.#####.#.###.#.#.#.#.####### +#.#.........#.#.#...#.....#...#...#...#...#.#.#...#.#.#...#.#.#.#.#.#...#.#.#...#.#.###.#...#...#...#...#.......#.....#.#.#...#.#.#.#.#...### +#.###########.#.#.#.#####.#######.#.#######.#.#####.#.#.###.#.#.#.#.#.###.#.###.#.#.###.#.#.#.###.#####.#.###########.#.#.#.###.#.#.#.#.#.### +#.#...#...#...#.#.#.#...#.......#.#.....#...#.....#.#.#...#.#.#.#.#.#...#.#.#...#.#...#.#.#.#.###...#...#.......#.....#...#...#.#...#...#...# +#.#.#.#.#.#.###.#.#.#.#.#######.#.#####.#.#######.#.#.###.#.#.#.#.#.###.#.#.#.###.###.#.#.#.#.#####.#.#########.#.###########.#.###########.# +#.#.#.#.#.#...#.#.#.#.#.#.......#.#.....#.#...#...#.#...#.#.#.#.#.#.###.#.#.#...#...#.#.#.#.#...#...#.......###.#.......#...#...###...#...#.# +#.#.#.#.#.###.#.#.#.#.#.#.#######.#.#####.#.#.#.###.###.#.#.#.#.#.#.###.#.#.###.###.#.#.#.#.###.#.#########.###.#######.#.#.#######.#.#.#.#.# +#.#.#.#.#.#...#.#.#.#.#.#.......#.#.....#.#.#.#.#...#...#.#.#.#.#.#.#...#.#...#...#.#.#.#.#...#.#...#.....#...#...#.....#.#.........#...#...# +#.#.#.#.#.#.###.#.#.#.#.#######.#.#####.#.#.#.#.#.###.###.#.#.#.#.#.#.###.###.###.#.#.#.#.###.#.###.#.###.###.###.#.#####.################### +#...#...#...###...#...#.........#.......#...#...#.....###...#...#...#.....###.....#...#...###...###...###.....###...#####...................# +###########################################################################################################################################.# diff --git a/solutions/solutions.cabal b/solutions/solutions.cabal index 2154232..766b76e 100644 --- a/solutions/solutions.cabal +++ b/solutions/solutions.cabal @@ -1093,5 +1093,10 @@ executable sln_2023_21 executable sln_2023_22 import: day main-is: 2023/22.hs - build-depends: containers, parallel + build-depends: containers, parallel, fgl ghc-options: -threaded + +executable sln_2023_23 + import: day + main-is: 2023/23.hs + build-depends: containers, array diff --git a/solutions/src/2023/23.hs b/solutions/src/2023/23.hs new file mode 100644 index 0000000..2ab1800 --- /dev/null +++ b/solutions/src/2023/23.hs @@ -0,0 +1,109 @@ +{-# Language LambdaCase, ImportQualifiedPost #-} +{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} +{-| +Module : Main +Description : Day 23 solution +Copyright : (c) Eric Mertens, 2023 +License : ISC +Maintainer : emertens@gmail.com + + + +A brute-forced approach. + +-} +module Main (main) where + +import Advent (getInputArray, arrIx) +import Advent.Coord (cardinal, coordRow, east, north, south, west, Coord(C)) +import Advent.Search (bfs, dfs) +import Data.Array.Unboxed (bounds, UArray) +import Data.List (sortBy) +import Data.Map (Map) +import Data.Map qualified as Map +import Data.Ord (comparing) +import Data.Set (Set) +import Data.Set qualified as Set + +main :: IO () +main = + do input <- getInputArray 2023 23 + let (_, C ymax _) = bounds input + let path = [length s | (C y _,s) <- dfs (step input) (C 0 1, Set.empty), y == ymax] + print (maximum path) + + let input' = buildPaths input + let solvable here seen = + any (\x -> coordRow x == ymax) $ + bfs (\c -> [next | (next, _) <- Map.findWithDefault [] c input' + , Set.notMember next seen]) here + + let search _ [] = [] + search best ((C y _, dist, _):xs) | y == ymax = dist : search best xs + search best ((here, dist, seen):xs) + | Map.findWithDefault (-1) (here, seen) best < dist = + search (Map.insert (here,seen) dist best) ( + [(next, dist+dist1, Set.insert here seen) + | (next, dist1) <- sortBy (flip (comparing snd)) + (Map.findWithDefault [] here input') + , Set.notMember next seen + , solvable here seen + ] ++ xs) + | otherwise = search best xs + + print (maximum (search Map.empty [(C 0 1, 0, Set.empty)])) + +buildPaths :: UArray Coord Char -> Map Coord [(Coord, Int)] +buildPaths input = go [C 0 1] Map.empty + where + isIntersection c = + 2 < length [ + c' + | c' <- cardinal c + , cell <- arrIx input c' + , isOpen cell + ] || coordRow c == ymax + (_,C ymax _) = bounds input + + go [] acc = acc + go (x:xs) acc + | Map.member x acc = go xs acc + | otherwise = go (map fst ends ++ xs) (Map.insert x ends acc) + where + ends = + map (\(p:path) -> (p, length path)) $ + filter (isIntersection . head) $ + bfs next [x] + + next (c:_) | c /= x, isIntersection c = [] + next xxs@(c:cs) = + [ c' : xxs + | c' <- cardinal c + , c' `notElem` cs + , cell <- arrIx input c' + , isOpen cell + ] + next [] = undefined + +step :: UArray Coord Char -> (Coord, Set Coord) -> [(Coord, Set Coord) ] +step input (c, seen) = + [ (c', Set.insert c seen) + | c' <- cardinal c + , cell <- arrIx input c' + , case cell of + '.' -> True + '>' -> c' - c == east + 'v' -> c' - c == south + '^' -> c' - c == north + '<' -> c' - c == west + _ -> False + , Set.notMember c' seen ] + +isOpen :: Char -> Bool +isOpen = \case + '.' -> True + '>' -> True + 'v' -> True + '^' -> True + '<' -> True + _ -> False