From 16987a4bf8d3afce6d0426afb5144205305902ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20H=C3=B6lting?= <87192362+moritz-hoelting@users.noreply.github.com> Date: Wed, 13 Dec 2023 12:14:28 +0100 Subject: [PATCH] day 13 --- Cargo.lock | 8 + day-13/Cargo.toml | 12 + day-13/src/bin/input.txt | 1339 ++++++++++++++++++++++++++++++++++++++ day-13/src/bin/part1.rs | 65 ++ day-13/src/bin/part2.rs | 125 ++++ 5 files changed, 1549 insertions(+) create mode 100644 day-13/Cargo.toml create mode 100644 day-13/src/bin/input.txt create mode 100644 day-13/src/bin/part1.rs create mode 100644 day-13/src/bin/part2.rs diff --git a/Cargo.lock b/Cargo.lock index e1c86a8..ebd8d30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -151,6 +151,14 @@ dependencies = [ "nom", ] +[[package]] +name = "day-13" +version = "0.0.0" +dependencies = [ + "indoc", + "rayon", +] + [[package]] name = "deprecate-until" version = "0.1.1" diff --git a/day-13/Cargo.toml b/day-13/Cargo.toml new file mode 100644 index 0000000..f9502f0 --- /dev/null +++ b/day-13/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "day-13" +version = "0.0.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rayon.workspace = true + +[dev-dependencies] +indoc.workspace = true diff --git a/day-13/src/bin/input.txt b/day-13/src/bin/input.txt new file mode 100644 index 0000000..6436c82 --- /dev/null +++ b/day-13/src/bin/input.txt @@ -0,0 +1,1339 @@ +.###...####.. +###...#....#. +###...#....#. +.###...####.. +###.#........ +#####.#....#. +##.#..######. +####.#..##..# +..#....####.. +#.##.##.##.## +#.#...#.##.#. +.###.##.##.## +#.#....#..#.. +..###.##..##. +##.#..#....## + +....#..#####... +....#.##.#..##. +......#.#.###.. +.##........##.# +######..#..#.#. +....#.#.#.#..#. +#..##...#...### +.##..###.###### +.##..#.#.#....# +.##...####.#.## +.....#....##### +.....#....##### +.##...######.## +.##..#.#.#....# +.##..###.###### +#..##...#...### +....#.#.#.#..#. + +.#..#..#### +.#....#.### +...#####..# +##..#.#.### +.####.###.. +.#.#..##### +##.##..##.. +##.##..##.. +.#.#..##### + +#..##...### +#..##..#... +#..##..#... +#..##...### +#####..#.## +#.##..##### +#..####.#.# +.##.#.#.#.. +.....#####. +####..##### +#..#.#.###. +#..#.#..#.# +#..#.##.... + +....#.# +####.## +....#.. +...##.. +.##.... +......# +.##.... +######. +.##..#. +#..#..# +####.## +.##...# +.##...# +####.## +#..#..# +.##..#. +######. + +..##..##.....#... +.##.#..###..#..#. +###...###.#...##. +#..#.###...#.###. +#..#.###...#.###. +###...###.#..###. +.##.#..###..#..#. +..##..##.....#... +#..#..#.#.#.#.##. +#.#..##.##..#.#.# +##....####.####.. +##.###.#.#.#####. +##.###.#.#.#####. + +##..##. +#.#.##. +#.#.##. +##..##. +###.#.# +.#.#..# +..#...# +..##... +.##...# +.##.#.# +.##.#.# +.##.#.# +..##... + +##########....##. +##.#..#.###.#.##. +...####...##..##. +#.######.#.##.... +##.####.###.#...# +##......##.#.#..# +.#..##..#.##.#..# +##..##..###.##..# +#...##...######## +....##....####..# +..######..#.##..# +...#..#....#..##. +.#.#..#.#.####..# + +.##..## +#.##### +..#.### +#.###.. +####... +#####.. +#.###.. +..#.### +#.##### +.##..## +...#... + +.##...#..##.##. +.#.#######..#.. +.##..##.##.#.## +.##.##.#..###.# +.##.##.#..###.# +.##..##.##.#.## +.#.#######..#.. +.##...#..##..#. +..######.###... +##.#.#.##.#..#. +#.#...####.#... +#.#...####.#... +##.#.#.##.#..#. + +.##.##.##.... +....#.##.#### +....#.##.#### +.##.##.##.... +####.#.##.... +....#.###.#.# +.#.#.###..... +###.#....#### +.##.####..### +.##.####..### +###.#....#### +.#.#.###..... +..#.#.###.#.# +####.#.##.... +.##.##.##.... + +#.##....#.#.# +#..#.######.. +...##..###.## +....#..###.## +#..#.######.. +#.##....#.#.# +.#.....#.##.. +....#.##..#.# +....#.##..#.# +.#.....#.##.. +#.##....#.#.# +#..#.######.. +....#..###.## + +#.##...#..... +.##.###.#..#. +##..#.##..##. +.#.#.#...#### +..#.###.##.#. +###.##.####.# +###.##.####.# +..#.###.##.#. +.#.#.#...#### +##..#.##..##. +.##.###.#..#. +#.##.#.#..... +.#.###...#.## +.....##.##.#. +.....##.##.#. +.#.###...#.## +#.##.#.#..... + +#...###.# +##.#..##. +.##..#..# +#....###. +#....###. +.##..#..# +##.#..##. +#...###.. +#...###.. +##.#..##. +.##..#..# + +##.#..##..#.### +###........###. +###........###. +##.#..##..#.### +##.#..##..#..#. +..##.####.##... +..............# +..##..##..##..# +###........###. +##....##....### +####..##..##### +#...##..##...#. +#..##.##.##..#. + +####.## +...#.## +...#.## +.###.## +#.#.... +#..#... +####.## +.#..### +##..### +##.#.## +..##.## + +###.###..###.## +..############. +...#..####..#.. +..#.########.#. +....##.##.##... +..##.##..##.##. +##.#........#.# +...#..####..#.. +##.#..####..#.# +##.##......##.# +##...#.##.#...# +.....#.#..#.... +#####.#..#.#### +##.#.##..##.#.# +##..########..# +##..#.####.#..# +....#.#..#.#... + +#.#.#.####. +##...#..... +.##......## +.##......## +##...#..... +#.#.######. +#....#..... +##.######## +...##.....# +.#.#.#..... +.#.#.#..... + +##.###..#.# +#..###..#.# +.#...###.#. +..##...#..# +###.#..###. +###.#..###. +..##...#..# + +..#.#.. +..#.#.. +.##.... +.##..#. +..#...# +####.#. +#.#.... +##.#... +##.#... +#.#.... +####.#. +..#.#.# +.##..#. + +###..## +.##..#. +#####.. +#####.. +.##..#. +###..## +..##### +.#.#### +.#..### + +.#....##....# +.#.##.##.##.# +#.#..#..#..#. +...##....##.. +##....##....# +#.#..#..#..#. +#............ +..###....###. +###..####..## +##....##....# +..#..#..#..#. +###..####..## +##.##.##.##.# + +.........##.### +.........##.### +###.#.#..#....# +......#...###.# +#.#......##.##. +.##.######...#. +#######....#### +######.##.....# +#.#...##..##### +####..##..#..## +##.######.#.#.# +##...##..###... +...#.....#.###. +...#.......###. +##...##..###... + +......#....#..#.. +..##......#....#. +...#.###.######## +.....##.#........ +.##....#......... +..###..##........ +..#.##...######## +###..##.#.#.##.#. +###..##.#.######. + +....#...#.#.. +##...####...# +#.##...#.##.. +#.##...#.##.. +##...####...# +....#...#.#.. +##...#..#.#.# +#.#.#.#..#### +#.#..##..##.# +.####.#.#.... +###...##.##.. +###..###.##.. +.####.#.#.... + +...#### +..#.##. +....##. +##....# +##.##.. +##.##.. +##....# +..#.##. +..#.##. +...#### +...###. +..#..## +..#.### +##..#.# +..##.#. +##.#.## +...#..# + +#....#...#.#.##.# +##..##...###.#.## +##..###...#...... +.####.#.##.##...# +......#.#...##..# +#....###.#.####.# +.......##...#...# +######.#.#...###. +.#..#.##..##...#. +.#..#..##...#...# +.#..#..##...#.#.# + +.#.#..# +.#.#..# +#.##... +#...##. +.#.#### +.#..##. +.#..##. +####..# +##..... + +#....#... +.#...#..# +.#...#..# +#....#... +.#....##. +..####### +..#####.# +.#....##. +#....#... + +.###..### +.#.###.## +#.#.#.### +.##..##.. +#........ +#.#.##.## +.####.### +.##...... +.##..#.## +#.###..## +.####..## +....##... +###..##.. +.##..##.. +....##... + +..#..## +..#..## +..#...# +#...### +###.#.# +#.#.#.. +.#.#.## +.#.#.#. +#.#.#.. +###.#.# +#...### + +..####..##....##. +........##....##. +########.#....#.# +.#....#.#.####.#. +#.####.#........# +##.....###....### +##....##.##..##.# +##....##.######.# +##....###......## +..####..#.#..#.#. +##.##.##..#..#..# + +#....###.....###. +#....###.....###. +.##.#.#...#..#### +######.#..##...## +..##..###...#.### +..###..###....### +.###.#.#.#..#.### +.###.#.#.#..#.### +..###..###....### +..##..###...#.### +######.#..##...## +.##.#.#...#..#### +#....###.....##.. + +#.###....#.#..# +........###.... +........###.... +#.###....#.#..# +.#.#..#.#.#...# +....#.#...#.... +.#.#...#.#...## +.....#.#.###### +###....##.###.# +###....##..##.# +.....#.#.###### + +#..##..## +.##..#### +#######.. +.....##.. +.##...... +....###.. +#####..## +.......## +##.#...## +#..#..### +.....#### +#####.... +#..#..... + +#.####.##.# +#.####.##.. +###..##.#.. +..#.#..#..# +##.#...#.#. +#.###..##.# +#.###...#.. +.#....##.## +..##.##.#.. +##.##...### +##.##...### +..##.##.#.. +.#....##.## +#.###...#.. +#.###..##.# + +.###..###.... +...#.#..#..## +...##........ +...##........ +...#.#..#..## +.###..###.... +#.#.#.#.##### +......###.##. +#.####...#... +#.###.##..... +#.....##...## +.#..#.#...#.. +#..#.##.###.. + +.#.#.##..#.#####. +.#.#.##..#.#####. +..##.#.###.#..##. +#.####..#....###. +#.#.##.##.####.#. +.###..#...#..#..# +.##...#...#..#..# +#.#.##.##.####.#. +#.####..#....###. + +####... +....#.. +...##.. +#..#.## +#..#..# +....##. +....##. + +###.#........ +###.#........ +.....###..### +.#.##.##..##. +.##...#.##.#. +##..#..####.. +#..#.#.####.# +#..####....#. +#....#..##..# +.#.###......# +.#.#.#......# +.#.####.##.## +#.####.#..#.# +......######. +##.####.##.## +..###.##..##. +#####.######. + +.#.##..####..## +#...#.#.##.#.#. +#...#..####..#. +#...#..####..#. +#...#.#.##.#.#. +.#.##..####..## +#..#...####...# +.###...####...# +#.##..##..##..# +#..##.##..##.## +#.##.###..###.# +..#...##..##... +.#.#....##....# +.##..#..##..#.. +##...#......#.. +.#....#....#... +##.#....##.#..# + +#......###### +..####..#..## +.##..##..#..# +#..##..##.### +#..##..##.### +.##..##..#..# +..####..#..## +#......###### +.##..##.....# +..#..#..##... +##.##.##..##. +....#....#.## +.#.##.#.#.... +.#.##.#..###. +.........##.# + +#######.##.## +#.##.#.#.##.. +##..####..... +..##....###.# +##..###..#... +#....#...#... +......##..... + +#..####..#... +...#..#....## +....##.....## +..#....#..#.. +....##......# +..#....#..### +##..##..##.#. +..##..##..... +...#..#...### +###....###... +............# +..######...#. +............# +...####....#. +############. + +.##.#####.. +##.....#.#. +##..###.### +..#.#.#...# +###....#... +###......#. +.##......#. +####..##### +####..##### +.##......#. +###......#. + +##.....##.....### +.####..##..####.. +#.#.#.####.#.#.## +....##.##.##..... +#####......###### +#..#..#..#..#..## +#.####.##.####.## +.###..#..#..###.. +#..###.##.###..## +###.#..##..#.#### +#.#..#####...#.## +#.#.#.#..#.#.#.## +.##.#..##..#.##.. + +###.##....# +..#####..## +..##.##..## +###.##....# +...#....... +.#.#.#....# +.#..####### +##.##...... +###..#....# + +#.#..#..# +.######.. +###..###. +..#..#... +#.####.#. +#..##..#. +#.#..#.## +.#.##.#.# +###..###. +#.#..#.## +#......## +#......## +#......## +#......## +#.#..#.## + +..##..####.#.#. +..##..####.#.#. +.#.#.##.##...## +##.#....#.##..# +...#...###.#.## +..##.#.#.#...## +..#.##..##..#.# +##..#####.....# +...##.##.##.#.. +...#.##.##.##.# +####.#.####.#.# + +.####.#.. +.####.#.. +..#.###.. +.##.##.## +..###.### +###..#.#. +.##....## +##.#.#.#. +##.#.#.#. +.##....## +###..#.#. +...##.### +.##.##.## +..#.###.. +.####.#.. + +..##...## +.#..#.#.# +#....###. +######..# +........# +######.#. +#.##.#### +..##..... +##..##..# +......##. +.####.#.# +######.## +.#..#..## +.#..#...# +######.## + +##########..##... +#..#..#..#....##. +...#..#....##.... +....##....#.#..#. +.##.##.##....#.## +.##.##.##.##..### +..........#..###. + +#####..#####.##.# +#.##....##.#..... +#...#..#...#..##. +#.###..###.#..... +.#..####..#.##### +##..####..###.##. +##...##...###.##. +#..######..#..... +#..######..#.#### +.#..####..#...... +...##..##...#.##. +#.#.#..#.#.##.... +.###....###..#..# +.##.#..#.##.#.... +#####..#####..... + +#.#.##.###.#... +##.....#.##.### +...#.##....#... +#......####.### +##.....####.### +...#.##....#... +##.....#.##.### +#.#.##.###.#... +#######..#...## +.##.#..#.###... +..#.#.######### + +#..##....####.... +#..##....###..... +.###########..... +...##.#.#....###. +....##..#.#..#.## +....##..#.#..#.## +...##.#.#....###. +.###########..... +#..##....###..... +#..##....####.... +.#.#.#..#.#...... +..#.####..##..#.# +....#..##.#..#... + +##........### +####....####. +###.#..#.#### +..###..###..# +..##....##..# +.##########.. +###.#..#.#### +..###..###... +..#..##..#..# + +#.##..##.#.#.#. +.#..##..#.###.# +.#..##..#.###.# +#.##..##.#.###. +#.######.###.## +...#..#...##### +#..#..#..##.... +#.##..##.#.#.#. +..######..###.# + +#.######.##.# +##..##...##.. +#....#.##..## +.##....#....# +..#....#....# +#....#.##..## +##..##...##.. +#.######.##.# +#.##.###....# + +..##.##.. +####.#..# +#.#...#.. +..#...... +.##...... +#.#...#.. +####.#..# +..##.##.. +.###.#.## +#..##.... +.###..### +...####.. +#####.##. +#..#.##.# +#..#.##.# + +..#.#..###### +#..#..###.#.. +#..####.#..#. +##..##.....## +...###...#.## +###.#....#### +######.##.#.. +.##.###.##.## +.##.#.####### +.#.#.#..##... +.#.#####.#### +.#.#####.#### +.#.#.#..##... + +#...#..#...#.#. +#...##.##..###. +.##.#...##.#... +.##.#...##.#... +#...##.##..###. +#...#..#...#.#. +##.#...###.#### +...#.#.#.##.... +#.#...######.#. +#..##...#####.# +.###.#.###.#.## +.###.#.###.#.## +#..##...#####.# +#.#...####.#.#. +...#.#.#.##.... +##.#...###.#### +#...#..#...#.#. + +..##...#.#..### +..##...#.###... +.#..#....###.#. +....#..#..#.### +.......##.##.#. +##..##...#.##.. +#######.#.##..# +#######.#.##..# +##..##...#.##.. +.......##.##.#. +....#..#..#.### + +.##...#.##### +.##.#.#.#.### +###.#.#.#.### +.##...#.##### +....#..#..#.. +#######..##.. +###.....#.#.. +###...#.###.. +#.#..#.###... +.###.#.#..#.. +#.##.##.#..## + +#...#..##.### +#.#.#.##.#..# +##.##..#..#.. +####.#..##.## +...##.#.##.## +##.#....#.#.. +#..##.#...#.. +#..#.##.#.... +..#........## +..#........## +#..#.##.#.... + +######.#..##.##.# +..#######.#...##. +.#####.#.#.#...## +#.##..#.######... +.##..#..#.#..#### +.###..###..##...# +#...######..#.### +####.#.#..##..#.# +####.#.#..##..#.# +#...######..#.### +.###..###..##...# +.##..#..#.#..#### +#.##..########... +.#####.#.#.#...## +..#######.#...##. +######.#..##.##.# +######.#..##.##.# + +#.##..##.#### +..#.##.#..... +###.##.###### +#.#....#.#### +#.##..##.#### +..#....#..##. +.########.##. +.###..###.##. +#..####...##. +#..#..#..#..# +##......##### +####..####..# +..#.##.#..... +..#.##.#..##. +###.##.###..# +..##..##..##. +.###..###.##. + +##....###.####### +##....###..###### +.##.#.##..###.#.# +###..####.#.##### +##.########..#.## +#.##.##...#.#.##. +.#...#.........#. +.#...#.........#. +#.##.##...#.#.##. +##.########..#.## +###..####.#.##### +.##.#.##..###.#.# +##....###..###### +##....###.####### +.###..########### +###..##..##..###. +#.#....#..#.#.### + +#.##..# +..#.... +.###..# +#...##. +.#.#### +.#.#### +#...##. +.###..# +..#.... +#.##..# +#.##### +#.###.# +##.#..# + +.#.#.####.#.##.## +...#.####.#.##.## +....#....#...#.## +#..##.##.###...#. +#..##..#......#.# +.###..#.##.#.#### +.#...#.##.##.##.# +#..##.##.#..#..#. +#.....##.#.###### +..##....#..#...## +.....#.#...#....# +.....#.#...#....# +..##....#..#...## + +####..# +...#### +.##.... +###.... +..#.##. +###.##. +###.##. +..#.##. +#.#.... + +..#.#....#.#. +##...#..#...# +....#.##..... +..#...##...#. +..##########. +###.##..##.## +####......### +..#........#. +##.########.# + +#.#.##...####..#. +.#####.###.#.#### +....###.##....... +.###.#.#..##.#.#. +##.#.###.##..###. +##.#.###.##..###. +.###.#.#..##.#.#. +....###.##.#..... +.#####.###.#.#### +#.#.##...####..#. +.#..##.....####.# +#.##...#.##..#### +#.##...#.##..#### +.#..##.....####.# +#.#.##...####..#. + +..##..#.#..#.## +..#.#..##..#### +##.#...###....# +..####.#.#.#.## +..####.#.#.#.## +##.#...###....# +..#.#...#..#### +..##..#.#..#.## +.....##.#...#.. +####...##...### +..#...##...#### +##.....#.#..### +##...####..##.. +..##.#####.##.# +##.#.##..#.#.## +..##......#.#.. +....#..#.####.. + +.#.#### +####.#. +##.###. +..##..# +##..#.# +...#.#. +####..# +####..# +...#.#. + +##......#.....#.. +.#.###..##..#..#. +....###.#.######. +..##.###....##### +##.#.#.##..###### +...#######.#..### +..#...#.##.#..### +..#...#.##.#..### +...#######.#..### + +.##.### +.#..### +.##.#.. +###.#.# +.#.#..# +#.####. +##..#.# +#.###.# +######. +#.####. +#....#. +#....#. +#.####. + +##..##..##..### +#....#..#....## +..#.#.##.#.#... +#####.##..##### +###.##..##.#### +#.....##.....## +#####.##.###### + +.#..##.#..# +####.##.##. +...##.#.##. +#.#....##.. +##..####### +.#.#..#..## +.#.#..#.### +.........#. +##..#...... +##..#...... +.........#. +.#.#..#.### +.#.#..#..## + +.##..#.##........ +##..##....##..##. +##.###....##..##. +.##..#.##........ +.###..##.###..### +...##..#...####.. +##.#.##.#.#....#. +#####..##..#..#.. +...##.###.#.##.#. +##.#...###.####.# +.#..##.#...#..#.. +....####....##... +...#..##.###..### + +#..######.##.## +....#..###..### +....#..###..### +#..######.##.## +##.###..######. +#......#.#..#.# +.#.#.########## +##.###.#......# +####.####.##.## +#...##..####### +#...#.####..### + +.#......#.# +..#.##.#..# +#..#..#..#. +.##.##.##.. +.#......#.. +##......### +.#.#..#.#.. +....##....# +##......### +#..#..#..#. +#..####..## +..........# +##.#######. +..#.##.#..# +..#.##.#..# + +..######..### +###....####.. +####..####... +.#.####.#...# +#.#....#.#... +#........#... +#........#... +##......##... +#........#... + +.#..####...##.##. +##.#.#.#...#.##.# +####.##..#.##..## +#.....#.#..##.##. +#####.#####.####. +#####.#####.####. +#.....#.#..##.##. +####.##..#.##..## +##.#.#.#...#.##.# +.#..####...#####. +.#.##..###.#..#.. +#..#.#..#....#.#. +#.##..####..#.##. +##..##.#.###.#.## +##..##.#.###.#.## +#.##..####..#.##. +#..#.#..#....#.#. + +...#.##..#### +.#.#...#..#.# +#.#########.# +#.#..##..#... +####..#.###.# +####....###.# +#.#..##..#... +#.#########.# +.#.#...#..#.# +...#.##..#### +......#..#..# +......#..#..# +...#.##..#### + +.....##..##...... +...##.....###...# +#.#.########.#.#. +.####..##..####.# +#####.####.#####. +#####.####.#####. +.####..##..####.# + +#..#..##..# +....#....#. +#..#..##..# +.....####.. +.##........ +.....####.. +....######. +.##.##..##. +#....#..#.. +....##..##. +.##.#....#. + +...##....#.##..## +#...#.#..##...... +.##.##..#...##... +.###.#.....#.#... +##.#...#.#.##.#.# +##.#...#.#.##.#.# +.###.#.....#.#... +.##.##..#...##... +#...#.#..##...... +...##....#.##..## +.#...#.#.#.###... +...#.###..#....## +...#.####.#....## + +##.##..###.#. +##.##..###.#. +..##..#...... +#..##.####### +###.##.#....# +..#.###..##.. +#.#.#.#...... +.....####..## +.....####.### +#.#.#.#...... +..#.###..##.. + +###..## +###..## +.#.#.## +.##.#.# +##..### +.#..### +..#.#.. +.####.. +.##..## +.##.#.. +#.###.. + +#......####.##.## +..##.##..###..### +..##..#..###..### +#......####.##.## +#..###.###......# +..#.#...####..### +..#..#####.#..#.# +.##.#.#..##....## +...#.####..#..#.. +##.#..#.#..####.. +#.#.#.#.##......# + +.##.#####.##... +.#.#.##..###.## +.#.#.##..###.## +.##.########... +###.##.#.##.### +#####..#.#...## +....##...#.#### +.##.##.#.#.#### +#.#..#######.## + +###..###..##. +..####..#.... +#.#..#.#.#### +#.#..#.###..# +###..######## +#.####.#####. +##.##.##..... +.##..##.#.... +#.#..#.##.... +.#....#...... +.#....#.#.##. + +#..#.##.#..####.. +.#........#.#..#. +.####..####..##.. +###.#..#.#####.## +#..........###... +#..........###... +###.#..#.#####.## +.####..####..##.. +.#........#.#..#. +#..#.##.#..####.. +#.#..##.##.####.# + +##.###..##. +##.##...##. +..##....#.# +###.####.## +...####.### +###.##.#.#. +##.###.#... + +###.#####.. +#######...# +##..##.##.# +.#..#..#.#. +..##..#.#.. +#.##.#..##. +##..##.#... +........#.. +#.##.###### +.####....#. +######....# +######....# +.####....#. + +#..###.#. +###..##.. +...#.##.# +#..#..### +#..#..### +...#.##.# +###..##.. +#..###.#. +.#.#####. +#..##.#.. +.#.#.#... +.#.#.#.## +###.#..## +##...##.# +.#...##.# + +....###.##. +.##..#####. +....#...#.# +.##.....##. +.....###..# +......#.### +......#.### +.....###..# +.##.....##. +....#...#.# +.##..####.. +....###.##. +#..##.#.... +#####.#.### +.##.#####.. +.....#..#.. +.##.#..#..# + +.#.##.#..#.##.#.# +#.####....####.## +###..######..#### +#.....##.#.....#. +#....#.##.#....#. +####.######.####. +...####..####...# +#...#.####.#...## +#...#.####.#...## +...####..####...# +####.######.####. + +###..#..#..###### +#.#...##...#.##.# +##..#.##.#..####. +...##....##...... +#.##.#..#.##.##.# +####..##..####### +#.#.##..##.#.##.# +#.####..####.##.# +##.###..###.####. +.###......###..## +#.#..####..#.#### +##..#....#..####. +.#.#.#..#.#.#..#. +###..#..#..###### +.##.#.##.#.##..## +#.#.#....#.#.##.# +#..#..##..#..##.. + +.#..##..#.#..#.#. +.#..##..#......#. +#..###...##..##.. +.##.##.##..##..## +.#.####.#..##..#. +..#....#..#..#..# +.##.##.##.#..#.## +#.#.##.#.#.##.#.# +###....########## +##.#..#.###..###. +...#..#...#..#... +#.##..##.#....#.# +.##.##.##.#..#.## \ No newline at end of file diff --git a/day-13/src/bin/part1.rs b/day-13/src/bin/part1.rs new file mode 100644 index 0000000..5cc5081 --- /dev/null +++ b/day-13/src/bin/part1.rs @@ -0,0 +1,65 @@ +fn main() { + println!("{}", part1(include_str!("./input.txt"))); +} + +fn part1(input: &str) -> usize { + input.split("\n\n").map(process_pattern).sum() +} + +fn process_pattern(pattern: &str) -> usize { + let lines = pattern + .lines() + .map(|s| s.chars().collect()) + .collect::>>(); + let mut sum = check_for_reflection(lines.clone()) * 100; + let width = lines[0].len(); + let columns = (0..width) + .map(|i| lines.iter().map(|row| row[i]).collect::>()) + .collect(); + sum += check_for_reflection(columns); + + sum +} + +fn check_for_reflection(pattern: Vec>) -> usize { + (1..pattern.len()) + .find(|i| { + let a = &pattern[0..*i]; + let b = &pattern[*i..]; + + a.iter().rev().zip(b).all(|(a, b)| a == b) + }) + .unwrap_or(0) +} + +#[cfg(test)] +mod tests { + use super::*; + use indoc::indoc; + + #[test] + fn test_part1() { + assert_eq!( + part1(indoc!( + " + #.##..##. + ..#.##.#. + ##......# + ##......# + ..#.##.#. + ..##..##. + #.#.##.#. + + #...##..# + #....#..# + ..##..### + #####.##. + #####.##. + ..##..### + #....#..# + " + )), + 405 + ); + } +} diff --git a/day-13/src/bin/part2.rs b/day-13/src/bin/part2.rs new file mode 100644 index 0000000..6ecf526 --- /dev/null +++ b/day-13/src/bin/part2.rs @@ -0,0 +1,125 @@ +fn main() { + println!("{}", part2(include_str!("./input.txt"))); +} + +fn part2(input: &str) -> usize { + input.split("\n\n").map(process_pattern).sum() +} + +fn process_pattern(pattern: &str) -> usize { + let lines = pattern + .lines() + .map(|s| s.chars().collect()) + .collect::>>(); + let width = lines[0].len(); + (0..lines.len()) + .find_map(move |i| { + let lines = lines.clone(); + (0..width).find_map(move |j| { + let mut local_lines = lines + .clone() + .iter() + .map(|row| row.to_vec()) + .collect::>>(); + let smudge = local_lines.get_mut(i).unwrap().get_mut(j).unwrap(); + *smudge = if smudge == &'#' { '.' } else { '#' }; + + let mut sum = check_for_reflection(local_lines.clone(), i) * 100; + if sum > 0 { + return Some(sum); + } + + let columns = (0..width) + .map(|i| local_lines.iter().map(|row| row[i]).collect::>()) + .collect(); + sum += check_for_reflection(columns, j); + + if sum > 0 { + Some(sum) + } else { + None + } + }) + }) + .expect("no reflection found") +} + +fn check_for_reflection(pattern: Vec>, must_include: usize) -> usize { + (1..pattern.len()) + .find(|i| { + let a = &pattern[0..*i]; + let b = &pattern[*i..]; + + let diff = must_include.abs_diff(*i); + + let zipped = a.iter().rev().zip(b).collect::>(); + + zipped.len() > diff && zipped.iter().all(|(a, b)| a == b) + }) + .unwrap_or(0) +} + +#[cfg(test)] +mod tests { + use super::*; + use indoc::indoc; + + #[test] + fn test_part2() { + assert_eq!( + part2(indoc!( + " + #.##..##. + ..#.##.#. + ##......# + ##......# + ..#.##.#. + ..##..##. + #.#.##.#. + + #...##..# + #....#..# + ..##..### + #####.##. + #####.##. + ..##..### + #....#..# + " + )), + 400 + ); + } + + #[test] + fn test_pattern_part2() { + assert_eq!( + process_pattern(indoc!( + " + #.##..##. + ..#.##.#. + ##......# + ##......# + ..#.##.#. + ..##..##. + #.#.##.#. + " + )), + 300 + ); + + assert_eq!( + process_pattern(indoc!( + " + #...##..# + #....#..# + ..##..### + #####.##. + #####.##. + ..##..### + #....#..# + " + )), + 100 + ); + } +}