From c4fd92b4467b6cd155d7c43da908987a17864ca6 Mon Sep 17 00:00:00 2001 From: Leandro Lisboa Penz Date: Sat, 23 Dec 2023 07:30:00 +0000 Subject: [PATCH] Day 23a --- Cargo.lock | 10 +++ Cargo.toml | 1 + day23/Cargo.toml | 10 +++ day23/input.txt | 141 ++++++++++++++++++++++++++++++++++++++++ day23/src/bin/day23a.rs | 63 ++++++++++++++++++ day23/src/lib.rs | 106 ++++++++++++++++++++++++++++++ 6 files changed, 331 insertions(+) create mode 100644 day23/Cargo.toml create mode 100644 day23/input.txt create mode 100644 day23/src/bin/day23a.rs create mode 100644 day23/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 58a574e..de96f0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -371,6 +371,16 @@ dependencies = [ "rayon", ] +[[package]] +name = "day23" +version = "0.1.0" +dependencies = [ + "aoc", + "color-eyre", + "nom", + "sqrid 0.0.24", +] + [[package]] name = "either" version = "1.9.0" diff --git a/Cargo.toml b/Cargo.toml index caa20a7..1a1d49d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,5 +25,6 @@ members = [ "day20", "day21", "day22", + "day23", ] diff --git a/day23/Cargo.toml b/day23/Cargo.toml new file mode 100644 index 0000000..cb14e60 --- /dev/null +++ b/day23/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "day23" +version = "0.1.0" +edition = "2021" + +[dependencies] +aoc = { path = "../aoc" } +color-eyre = "0.6.2" +nom = "7.1.3" +sqrid = "0.0.24" diff --git a/day23/input.txt b/day23/input.txt new file mode 100644 index 0000000..1b623f9 --- /dev/null +++ b/day23/input.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/day23/src/bin/day23a.rs b/day23/src/bin/day23a.rs new file mode 100644 index 0000000..ce8a464 --- /dev/null +++ b/day23/src/bin/day23a.rs @@ -0,0 +1,63 @@ +// Copyright (C) 2023 Leandro Lisboa Penz +// This file is subject to the terms and conditions defined in +// file 'LICENSE', which is part of this source code package. + +use day23::*; + +use std::collections::HashSet; + +pub type Sqrid = sqrid::sqrid_create!(141, 141, false); +pub type Pos = sqrid::pos_create!(Sqrid); +pub type Grid = sqrid::grid_create!(Sqrid, Cell); + +fn dfs(size: u16, grid: &Grid, pos: Pos, visited: &HashSet, end: Pos, steps: usize) -> usize { + if pos == end { + return steps; + } + let pos_t = pos.tuple(); + if pos_t.0 >= size || pos_t.1 >= size { + return 0; + } + if visited.contains(&pos) { + return 0; + } + if grid[pos] == Cell::Wall { + return 0; + } + let mut newvisited = visited.clone(); + newvisited.insert(pos); + if let Cell::Slope(dir) = grid[pos] { + let Ok(newpos) = pos + dir else { return 0 }; + dfs(size, grid, newpos, &newvisited, end, steps + 1) + } else { + Dir::iter::() + .filter_map(|dir| { + (pos + dir) + .ok() + .map(|newpos| dfs(size, grid, newpos, &newvisited, end, steps + 1)) + }) + .max() + .unwrap_or(0) + } +} + +fn process(size: u16, bufin: impl BufRead) -> Result { + let input = parser::parse(bufin)?; + let grid = Grid::try_from(input)?; + let start = Pos::try_from((1, 0))?; + assert_eq!(grid[start], Cell::Empty); + let end = Pos::try_from((size - 2, size - 1))?; + assert_eq!(grid[end], Cell::Empty); + let visited = Default::default(); + Ok(dfs(size, &grid, start, &visited, end, 0)) +} + +#[test] +fn test() -> Result<()> { + assert_eq!(process(23, EXAMPLE.as_bytes())?, 94); + Ok(()) +} + +fn main() -> Result<()> { + do_main(|| process(141, stdin().lock())) +} diff --git a/day23/src/lib.rs b/day23/src/lib.rs new file mode 100644 index 0000000..950ce81 --- /dev/null +++ b/day23/src/lib.rs @@ -0,0 +1,106 @@ +// Copyright (C) 2023 Leandro Lisboa Penz +// This file is subject to the terms and conditions defined in +// file 'LICENSE', which is part of this source code package. + +pub use aoc::*; + +use std::fmt; + +pub const EXAMPLE: &str = "#.##################### +#.......#########...### +#######.#########.#.### +###.....#.>.>.###.#.### +###v#####.#v#.###.#.### +###.>...#.#.#.....#...# +###v###.#.#.#########.# +###...#.#.#.......#...# +#####.#.#.#######.#.### +#.....#.#.#.......#...# +#.#####.#.#.#########v# +#.#...#...#...###...>.# +#.#.#v#######v###.###v# +#...#.>.#...>.>.#.###.# +#####v#.#.###v#.#.###.# +#.....#...#...#.#.#...# +#.#########.###.#.#.### +#...###...#...#...#.### +###.###.#.###v#####v### +#...#...#.#.>.>.#.>.### +#.###.###.#.###.#.#v### +#.....###...###...#...# +#####################.# +"; + +pub use sqrid::Dir; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub enum Cell { + #[default] + Empty, + Wall, + Slope(Dir), +} + +impl TryFrom for Cell { + type Error = Report; + fn try_from(c: char) -> Result { + match c { + '.' => Ok(Cell::Empty), + '#' => Ok(Cell::Wall), + '^' => Ok(Cell::Slope(Dir::N)), + '>' => Ok(Cell::Slope(Dir::E)), + 'v' => Ok(Cell::Slope(Dir::S)), + '<' => Ok(Cell::Slope(Dir::W)), + other => Err(eyre!("invalid cell {}", other)), + } + } +} + +impl From<&Cell> for char { + fn from(c: &Cell) -> Self { + match c { + Cell::Empty => '.', + Cell::Wall => '#', + Cell::Slope(Dir::N) => '^', + Cell::Slope(Dir::E) => '>', + Cell::Slope(Dir::S) => 'v', + Cell::Slope(Dir::W) => '<', + _ => unreachable!(), + } + } +} + +impl fmt::Display for Cell { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", char::from(self)) + } +} + +pub mod parser { + use aoc::parser::*; + + use super::*; + + fn cell(input: &str) -> IResult<&str, Cell> { + let (input, c) = character::one_of(".#^>v<")(input)?; + Ok((input, Cell::try_from(c).unwrap())) + } + + fn line(input: &str) -> IResult<&str, Vec> { + let (input, cells) = multi::many1(cell)(input)?; + let (input, _) = character::newline(input)?; + Ok((input, cells)) + } + + pub fn parse(mut bufin: impl BufRead) -> Result>> { + aoc::parse_with!(multi::many1(line), bufin) + } +} + +#[test] +fn test() -> Result<()> { + let input = parser::parse(EXAMPLE.as_bytes())?; + assert_eq!(input.len(), 23); + assert_eq!(input[0].len(), 23); + Ok(()) +}