From 7017b91d91f9fead2b86b940165bc1250dd0309b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 23 Dec 2023 10:57:08 +0100 Subject: [PATCH 1/4] 2023: d23: ex1: add input --- 2023/d23/ex1/input | 141 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 2023/d23/ex1/input diff --git a/2023/d23/ex1/input b/2023/d23/ex1/input new file mode 100644 index 0000000..8a1a97e --- /dev/null +++ b/2023/d23/ex1/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#.###.#.#.### +#...#.#...#.#.........#.#.#.#.#...###.#.#.#.#.#.#.#.........#...#.#.#.#.#.#.....#...#.#.#.......#.....###...#.....#...#.#.......#...#.#.#.### +#.###.#.###.#.#########.#.#.#.#.#####.#.#.#.#.#.#.#########.###.#.#.#.#.#.#.#######.#.#.#.#######.#########.#.###.#.#.#.#.#########.#.#.#.### +#.....#.....#...........#...#...#####...#...#...#...........###...#...#...#.........#...#.........#########...###...#...#...........#...#...# +###########################################################################################################################################.# From 1204116d6fe5b29d8175893f00632eeb5078bba3 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 23 Dec 2023 10:57:13 +0100 Subject: [PATCH 2/4] 2023: d23: ex1: add solution --- 2023/d23/ex1/ex1.py | 93 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 2023/d23/ex1/ex1.py diff --git a/2023/d23/ex1/ex1.py b/2023/d23/ex1/ex1.py new file mode 100755 index 0000000..2385fca --- /dev/null +++ b/2023/d23/ex1/ex1.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python + +import enum +import sys +from collections.abc import Iterator +from typing import NamedTuple, Optional + + +class Point(NamedTuple): + x: int + y: int + + +class Cell(enum.StrEnum): + PATH = "." + NORTH_SLOPE = "^" + SOUTH_SLOPE = "v" + WEST_SLOPE = "<" + EAST_SLOPE = ">" + + def neighbours(self) -> Iterator[Point]: + match self: + case self.PATH: + yield from ( + Point(-1, 0), + Point(1, 0), + Point(0, -1), + Point(0, 1), + ) + case self.NORTH_SLOPE: + yield Point(-1, 0) + case self.SOUTH_SLOPE: + yield Point(1, 0) + case self.WEST_SLOPE: + yield Point(0, -1) + case self.EAST_SLOPE: + yield Point(0, 1) + + def apply(self, pos: Point) -> Iterator[Point]: + for dx, dy in self.neighbours(): + yield Point(pos.x + dx, pos.y + dy) + + +Trails = dict[Point, Cell] + + +def solve(input: list[str]) -> int: + def parse(input: list[str]) -> Trails: + res: Trails = {} + + for x, line in enumerate(input): + for y, c in enumerate(line): + if c == "#": + continue + res[Point(x, y)] = Cell(c) + + return res + + def explore(trails: Trails, start: Point, dest: Point) -> int: + def recurse(start: Point, seen: set[Point]) -> Optional[int]: + if start == dest: + return 0 + if start not in trails: + return None + next_step = ( + recurse(n, seen | {n}) + for n in trails[start].apply(start) + if n not in seen + ) + distances = [dist for dist in next_step if dist is not None] + if not distances: + return None + return max(distances) + 1 + + res = recurse(start, {start}) + assert res is not None # Sanity check + return res + + trails = parse(input) + start, dest = Point(0, 1), Point(len(input) - 1, len(input[0]) - 2) + assert start in trails # Sanity check + assert dest in trails # Sanity check + sys.setrecursionlimit(10_000) + return explore(trails, start, dest) + + +def main() -> None: + input = sys.stdin.read().splitlines() + print(solve(input)) + + +if __name__ == "__main__": + main() From a42da85f1f472c1d9bb6a7f86ade7fc57c4a6852 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 23 Dec 2023 10:57:18 +0100 Subject: [PATCH 3/4] 2023: d23: ex2: add input --- 2023/d23/ex2/input | 141 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 2023/d23/ex2/input diff --git a/2023/d23/ex2/input b/2023/d23/ex2/input new file mode 100644 index 0000000..8a1a97e --- /dev/null +++ b/2023/d23/ex2/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#.###.#.#.### +#...#.#...#.#.........#.#.#.#.#...###.#.#.#.#.#.#.#.........#...#.#.#.#.#.#.....#...#.#.#.......#.....###...#.....#...#.#.......#...#.#.#.### +#.###.#.###.#.#########.#.#.#.#.#####.#.#.#.#.#.#.#########.###.#.#.#.#.#.#.#######.#.#.#.#######.#########.#.###.#.#.#.#.#########.#.#.#.### +#.....#.....#...........#...#...#####...#...#...#...........###...#...#...#.........#...#.........#########...###...#...#...........#...#...# +###########################################################################################################################################.# From 4047f428e104f29fefd0abb03499e1c3b37ddc5c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 23 Dec 2023 10:57:23 +0100 Subject: [PATCH 4/4] 2023: d23: ex2: add solution --- 2023/d23/ex2/ex2.py | 104 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 2023/d23/ex2/ex2.py diff --git a/2023/d23/ex2/ex2.py b/2023/d23/ex2/ex2.py new file mode 100755 index 0000000..fadce89 --- /dev/null +++ b/2023/d23/ex2/ex2.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python + +import copy +import sys +from collections.abc import Iterator +from typing import NamedTuple, Optional + + +class Point(NamedTuple): + x: int + y: int + + def neighbours(self) -> Iterator["Point"]: + for dx, dy in ( + (-1, 0), + (1, 0), + (0, -1), + (0, 1), + ): + yield Point(self.x + dx, self.y + dy) + + +Trails = set[Point] +Graph = dict[Point, dict[Point, int]] + + +def solve(input: list[str]) -> int: + def parse(input: list[str]) -> Trails: + res: Trails = set() + + for x, line in enumerate(input): + for y, c in enumerate(line): + if c == "#": + continue + res.add(Point(x, y)) + + return res + + def to_graph(trails: Trails) -> Graph: + graph: Graph = {p: {} for p in trails} + + for p in trails: + for n in p.neighbours(): + if n not in trails: + continue + graph[p][n] = 1 + + return graph + + # Remove every node which has exactly two neighbours (i.e: straight lines) + def condense_graph(graph: Graph) -> Graph: + graph = copy.deepcopy(graph) + nodes = list(graph.keys()) + + for n in nodes: + if len(graph[n]) != 2: + continue + (n1, d1), (n2, d2) = graph[n].items() + del graph[n1][n] + del graph[n2][n] + del graph[n] + graph[n1][n2] = d1 + d2 + graph[n2][n1] = d1 + d2 + + return graph + + def explore(graph: Graph, start: Point, end: Point) -> int: + def recurse(start: Point, seen: set[Point]) -> Optional[int]: + if start == end: + return 0 + if start not in graph: + return None + next_step = ( + (dist, recurse(n, seen | {n})) + for n, dist in graph[start].items() + if n not in seen + ) + distances = [ + (dist + steps) for dist, steps in next_step if steps is not None + ] + if not distances: + return None + return max(distances) + + res = recurse(start, {start}) + assert res is not None # Sanity check + return res + + trails = parse(input) + graph = to_graph(trails) + graph = condense_graph(graph) + start, dest = Point(0, 1), Point(len(input) - 1, len(input[0]) - 2) + assert start in graph # Sanity check + assert dest in graph # Sanity check + return explore(graph, start, dest) + + +def main() -> None: + input = sys.stdin.read().splitlines() + print(solve(input)) + + +if __name__ == "__main__": + main()