From c21c7ec8d25a5f5a42f8e2b606bf211b320e00db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Fuglede=20J=C3=B8rgensen?= Date: Sat, 23 Dec 2023 14:58:35 +0100 Subject: [PATCH] Add solution to 2023-12-23 --- 2023/day23/input | 141 ++++++++++++++++++++++++++++++++++++++++ 2023/day23/solutions.py | 37 +++++++++++ 2 files changed, 178 insertions(+) create mode 100644 2023/day23/input create mode 100644 2023/day23/solutions.py diff --git a/2023/day23/input b/2023/day23/input new file mode 100644 index 0000000..0db626e --- /dev/null +++ b/2023/day23/input @@ -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/2023/day23/solutions.py b/2023/day23/solutions.py new file mode 100644 index 0000000..d57f5b7 --- /dev/null +++ b/2023/day23/solutions.py @@ -0,0 +1,37 @@ +import networkx as nx +from networkx.classes.function import path_weight + +with open("input") as f: + ls = f.read().strip().split() + +N, M = len(ls), len(ls[0]) +s, t = (0, 1), (N - 1, M - 2) + +prev = {">": (0, -1), "<": (0, 1), "^": (1, 0), "v": (-1, 0)} +G1 = nx.grid_2d_graph(N, M, create_using=nx.DiGraph) +G2 = nx.grid_2d_graph(N, M) +for i, l in enumerate(ls): + for j, x in enumerate(l): + p = (i, j) + if x == "#": + G1.remove_node(p) + G2.remove_node(p) + elif dp := prev.get(x): + di, dj = dp + G1.remove_edge(p, (i + di, j + dj)) + +# Part 1 +print(max(map(len, nx.all_simple_edge_paths(G1, s, t)))) + +# Part 2 +# We contract all nodes with exactly two neighbours, keeping track of the +# distance along the way +us = [u for u in G2.nodes if len(G2.edges(u)) == 2] + +for u in us: + v1, v2 = list(G2.neighbors(u)) + new_weight = sum(G2.edges[u, v].get("d", 1) for v in (v1, v2)) + G2.add_edge(v1, v2, d=new_weight) + G2.remove_node(u) + +print(max(path_weight(G2, path, "d") for path in nx.all_simple_paths(G2, s, t)))