diff --git a/2023/Cargo.lock b/2023/Cargo.lock index f5a0cbc..be3fe92 100644 --- a/2023/Cargo.lock +++ b/2023/Cargo.lock @@ -198,6 +198,14 @@ dependencies = [ "itertools", ] +[[package]] +name = "day-13" +version = "0.1.0" +dependencies = [ + "color-eyre", + "itertools", +] + [[package]] name = "either" version = "1.9.0" diff --git a/2023/day-13/Cargo.toml b/2023/day-13/Cargo.toml new file mode 100644 index 0000000..e55d035 --- /dev/null +++ b/2023/day-13/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "day-13" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +color-eyre.workspace = true +itertools.workspace = true diff --git a/2023/day-13/input.txt b/2023/day-13/input.txt new file mode 100644 index 0000000..c9c2763 --- /dev/null +++ b/2023/day-13/input.txt @@ -0,0 +1,1377 @@ +.####..#.#.#.##.. +........#..##.... +..##..#.....#..## +......##.##.##### +######.#.####.... +..##....#..##.#.. +.#..#..#####.#... +..##...#..#...#.# +#######.#....#### + +#.###..#### +..#####.... +#.##...#### +##..#.##..# +##.#.##.##. +##.#.##.##. +##..#.##..# +#.##...#### +..###.#.... +#.###..#### +.##....#..# + +.##...#...##### +...######..#.#. +..#.#..#.####.. +#..#...##.##..# +#..#...##.##..# +..#.#..#.####.. +#..######..#.#. +.##...#...##### +#..#..#.#...#.# +####.#####..#.. +....#.##..##... +#..######..#.## +##.#...#..##.#. +##.#...#..##.#. +#..######..#.## +....#.##..##... +####.#####..#.. + +#####..#####.## +.............## +#..######..##.. +.##.#..#.##.#.# +....####....##. +#..##..##..###. +#.########.#.#. +.##..##..##...# +#..##..##..##.. +####....####..# +....####....#.. + +...#....##... +.#.##....#... +#..##.####.#. +#.#####.##.#. +##...#.##.#.# +##...#.##.#.# +#.#####.##.#. +#..##.####.#. +.#.##....#... +...#....##... +...#....##... +.#.##....#... +#..##.####.#. +#.###.#.##.#. +##...#.##.#.# + +####.##.#..#.#... +....##.####.#.#.. +....##.####.#.#.. +####.##.#..#.#... +..#####...####.## +#####..##.###...# +.##...##.....###. +.##...##.....###. +#####..##.###...# +..#####...####.## +#.##.##.#..#.#... + +#.##########. +##.#..##..#.# +..#.##..##.#. +#...#....#... +##.#......#.# +#.#.#....#.#. +###...##...## +###...##...## +#.#.#....#.#. +##.#......#.# +....#....#... + +....##....##..... +.####.####.####.. +###....##....###. +###....##....###. +.####.####.####.. +....##....##..... +..##..#..#..##..# +.###############. +.##.#..##..#.##.. + +####.#..#.####..# +####..##..####### +#.#.#.##.#.#.#### +##.#..##..#.##..# +.#####...####.... +.###.#..#.###.... +.##..#..#..##.... +..#.######.#..##. +#..#......#..#..# +######..######..# +#.##..##..##.#### +..##.####.##..##. +...##.##.##...##. +..#.#....#.#..##. +.##..#..#..##.##. +#####....######## +##..##..##..##### + +..###.#..#.## +#####.####.## +...##.#..#.## +...##.####.## +###.#......#. +###..######.. +###.......... +..##..##.#..# +...###.##.### + +##...####...### +##...####...### +#....#..#....## +##..........### +#.##########.#. +..#..#..#.##... +.#...####...#.# +#..#.####.#..#. +.##..####..##.# +###..####..###. +#..##.##.##..#. +#.#........#.#. +#.....##.....#. + +#..#####.#. +.#.#...#### +.##.#####.# +#...###.#.# +#..####.#.# +.##.#####.# +.#.#...#### +#..#####.#. +####..#..## +####....##. +####....##. +####..#..## +#..#####.#. +.#.#...#### +.##.#####.# + +.######.####... +..#..#....##... +..#..#....##... +.######.####... +###..######.##. +.........#..### +..#####.#.##### +#.#..#.##.....# +.##..##....#### +...##...##..#.. +.#....#.#.#..## +...##....#####. +.#.##.#.###.### + +###.#...#.#.##.#. +#.#...####...#..# +#.#...####...#..# +###.#...#.#.##.#. +..####..#####.... +.....###...#..### +.....###...#..### +..####..#####.... +###.#...#.#.##.## + +##.#..##.##.# +.#........... +.#####...##.. +##.#...#.##.# +...#.###.##.# +.##..#..#..#. +#.##..#...... +#..###..#..#. +#.#.##....... +...#.###.##.# +.#.###.#....# +##..#....##.. +#..########## +##.########## +##..#....##.. +.#.###.#....# +...#.###.##.# + +##.######.##. +...#....#..## +####....##### +...#.##.#.... +###..##..###. +#..######..## +..#.#..#.#..# +#.##.##.##.## +...##..##.... +##...##...### +##...##...### +...##..##.... +#.##.##.##.## +..#.#..#.#..# +#..######..## +###..##..###. +...#.##.#.... + +####..#.##### +#..#...##.##. +.##.##.###### +#..#...#..... +#..#.##..#### +###.#..#..... +#..###..#.... +#..#......##. +####..##..##. + +###...... +..#.##..# +...###### +...###... +###.##### +#..##.... +#..##.... +###.##### +...###... + +..##..######### +####.....#.#.#. +###.#..####.### +.#..##..####.#. +#.#.##.##...... +....####..#..## +###.##..##..... +.#..##....###.# +.#..##....###.# +###.##..##..... +....####..#..## +#.#.##.##...... +.#..##..####.#. +###.#..####.### +####....##.#.#. +..##..######### +..##..######### + +......#.##.#. +#....#......# +##..###....## +.#..#..#..#.. +#....######## +.#..#...##... +.#..#.##..##. +##..######### +..##........# +######......# +.####...##... +.#..#...##... +#....#......# +..##..#....#. +##..###....## + +.###.###. +#.#..#### +###.##.#. +###.##.## +#.#..#### +.###.###. +.###.###. +#.#..#### +###.##.## +###.##.#. +#.#..#### +.###.###. +#...#.#.# + +.#....#.. +.##...#.. +.###.##.. +#.##.#... +.####..## +#.#.#.### +..#...#.. +##...#... +##..####. +##..####. +##...#... +..#...#.. +#.#.#.### +.####..## +#.##.#... +.###.##.. +.##...#.. + +#..##....##.. +.##.#.##....# +#..#.#..#..#. +#####....##.. +....##.##...# +#..#...###### +#..####.#..#. +.##.###..##.. +....###...... +.##..#..####. +#..###.#.##.# +.......###### +.....####..## + +####.#..##.## +.##.########. +.##.#.#..##.# +....#.#.#.### +.##..#.##.### +#..##..###.## +#####.###.... +######.#.#..# +.##....###... +.........##.# +#####.##.#... +#..###.##.##. +....###.#..## +######.#..#.# +#..#.#.#..### +#..#.#.#..#.# +######.#..#.# + +.#.#.#### +.###.#..# +#..#..... +..#...##. +..#.##..# +.#.#..... +...#.#### +###...... +...###..# +...###..# +.##...... + +#....####.. +.##.##..### +.....####.. +.#..#...#.# +..#...#..#. +####.#.##.. +####.#.##.. +..#...#..#. +.#..#...#.# +.....####.. +.##.##..### +#....####.. +.....####.. + +.#..#..#. +#.#.####. +.#.###### +#..###### +####.##.# +####.##.# +....#..#. +..##....# +###...... +###...... +..##....# +....#..#. +.###.##.# + +.#.##...#..## +#.#.#.#...#.# +.##.....##.#. +.##..##..#### +...#.#####.## +#.#####..#... +#.#####..#... +.#.#.#####.## +.##..##..#### +.##.....##.#. +#.#.#.#...#.# +.#.##...#..## +.#.##...#..## + +####...##.#..##.. +#######........## +..#..##.#....##.# +##....##..###.#.# +.####..###...###. +..#.###.#..#.#..# +..#.###.#..#.#..# +.####..###...###. +##....##..###.#.# +..#..##.#....##.# +#######........## +####...##.#..##.. +#..#...#.##.##.#. +.###.#..#.###.#.# +.###.##.#.###.#.# +#..#...#.##.##.#. +####...##.#..##.. + +#...####.#..... +#..#.#.#.....#. +####.#.#....##. +#..#...#.#.#### +.##......#.##.. +.##...#####.... +.##.#..#....... +.##.#..#....... +.##...#####.... +.##......#.##.. +#..#...#.#.#### + +.###.#..... +...##..#.#. +##....##... +..#..#.#... +##.##.##..# +##.##.##..# +..#..#.#... +##....##... +...##..#.#. +.###.#..... +..#.#.###.# +##.##..#.## +##.##..#.#. + +.#....#.#.#.#.... +#.####.#...####.. +#..##..##.##..### +.#.##.#..#####.## +#..##..##.#....## +#.#..#.#.#.#.#... +.######....#.#... +#.####.#....#.### +...##...###..##.. +..#..#..#.##..#.. +#..##..#.#.##.#.. +.#....#.#..##..## +##..#.###.####.## + +.##..##.### +.######.#.. +###..###... +#.#..#.###. +##....##... +##....###.. +#..##..#.## +#########.# +.#.##.#..#. +..#..#...## +.#....#.##. +.#....#.##. +..#..#....# +.#.##.#..#. +#########.# +#..##..#.## +##....###.. + +#...#.#..#. +####.#..#.# +##.#..####. +#.###.#..#. +......####. +.###.###### +#.#.##.##.# +...###....# +.....#....# +##..#..##.. +##.#.###### +##.#.###### +##..#..##.. +.....#....# +...###....# +#.#.##.##.# +.###.###### + +#.#####...#...... +#.#####...#...... +.##...###..#.#... +.#.####.####...#. +....##..#.##...## +###...#..#.##...# +....##.#.##.#.##. +##.#.#....#####.# +..##.#.#..###.#.# +##.###.####.#...# +#..###.####.#...# +..##.#.#..###.#.# +##.#.#....#####.# +....##.#.##.#.##. +###...#..#.##...# + +##..### +.####.. +#....## +..##... +#.##... +##..### +#.##.## + +.#.#..#....##...# +.###..#....##...# +.#####.##..#.#..# +#.##.##.#........ +#.##.##.#........ +.#####.##..#.#..# +.###..#....##...# +.#.#..#....##...# +###..#..###.##.#. +##.....###.#..### +####...####..#### + +##..##.##.# +#...###..## +.#...###### +#..##...... +.########## +###........ +###.#...... +..#.#...... +#.#.####### +.#..###..## +#.#.#...... +.######..## +...#.###### +..#.#..##.. +..#####..## +#.######### +##.######## + +..##..#.. +#.#..##.. +#..#####. +.####...# +.####...# +#..####.. +#.#..##.. +..##..#.. +##..#.... +..#....## +..#....## +##..#.... +..##..#.. + +.#..#.... +#.##.###. +#....#### +#....##.# +#.##.#..# +##..##.#. +#....#.#. +#....#..# +#....##.# +#....#.#. +##..##.#. +#.##.#..# +#....##.# +#....#### +#.##.###. +.#..#.... +##..###.. + +...####.##..# +#.....####..# +...#...#.#..# +###..#.###..# +.#.#.##.#.##. +...#.##.#.##. +###..#.###..# +...#...#.#..# +#.....####..# +...####.##..# +.....###.#### + +#.##... +.#.#... +##.#.## +.#.#### +.#.##.. +.##.#.. +.###.## +#.#..## +..###.. +.####.. +.###... + +.##..##.########. +.#.##.#...####... +.######.#.#..#.#. +.##..##.##....##. +.######.#.####.#. +########..#..#..# +..#..#..#.#..#.#. +..#..#..#.#..#.#. +.#......#.####.#. + +#...###..##..## +.###..#####..## +.##.#.##.#.##.# +..#..###.##..## +#...#....##..## +##.#####..####. +#####...#.#..#. +###..#..###..## +###.###.####### +#...##...#....# +##.#.#.#.#.##.# +##.#.#.#.#.##.# +#...###..#....# + +.#.##.#..##.#.. +##..#.##.##..## +.#.#.#.....#... +#...###.####.## +#.#..#.##.##... +###..#.##.##... +#...###.####.## +.#.#.#.....#... +##..#.##.##..## +.#.##.#..##.#.. +...#.#...#.##.. +..###.#..####.. +##..####.#..... +######.##...### +..#.....#.##.## + +......# +......# +..#..#. +####.#. +..#.##. +##.##.. +..#.### +...###. +##.###. +...###. +..#...# +##...#. +##...#. +####.## +##.#.## +###..#. +.#.##.# + +..####..#.#...#.. +.#....#.######..# +.#.##.#.....#.... +.#.##.#.....#.... +.#....#.######..# +..####..#.#...#.. +..####..####.#### +##....##..#.###.. +.......##......#. + +###..##.. +..#.#..#. +###.####. +##..####. +...#....# +##.#.#### +...###### +...###### +..#.#..#. +..####### +##....... +..#..##.. +..#...... +##...##.. +#####..## + +##........##... +...######...... +..##....##..##. +###..##..###### +##..#..#..##### +..###..###..### +.....##.....#.# +..#.####.#...#. +###..##..####.. +...######.....# +..#..##..#..#.. +#...####...#..# +##.#....#.##... +###......###.#. +..###..###..#.. +###.#..#.####.. +..#..##..#..#.# + +#...##.#. +#...#..#. +...#.#... +.######.. +.....#.#. +.#...#### +..#..#... +..#..#... +.#...#### +.....#.#. +.######.. +...#.#... +#...#..#. +#...##.#. +#.#..#.## +#.#.##..# +.#.###.## + +.######....#.#. +.........#...## +.#....#.#.#.... +..#..#....#.### +#.####.##..#..# +...##...#..#### +...##...#..#### +#.####.##..#..# +..#..#....#.### +.#....#.#.#.... +.........#..### + +....###.#.. +#...#...### +#...#...### +....###.#.. +.......#.#. +#.##.##.### +##..#..#... +#####..#.## +##..#...... +##...#.#.## +#.#..##.#.. + +..####...##.# +..####....### +##.##.##..### +...##...##.#. +.##..##.##### +##.##.#####.. +..####...#.#. +........#...# +###..###..#.# +...##....#... +##....##..### +..####..##.## +##.##.###.##. + +##...####...# +...#......##. +#####.##.#### +##.#.#..#.#.# +###..#..#..## +....#....#... +...##.##.##.. + +.##.##... +.#...#... +###.#.### +#......## +.##.##### +###.#..## +.#....#.. +##...#... +#.##.#.## +#.##.#### +##...#... + +####.#..# +...##.### +##.....#. +..#..###. +..#..###. +##.....#. +..###.### +####.#..# +....#.#.# +.##.#..#. +..#..##.. +#.##.#.#. +#.##.#.#. +..#..##.. +.##.#..#. + +...#.#. +###.#.. +......# +#####.. +##..### +##..... +##.#... +##.#... +##..... +##..### +#####.. +...#..# +###.#.. + +..#.#.# +####.## +######. +...#.#. +...#... +..##..# +...###. +###.##. +#####.. +#####.. +######. +...###. +..##..# +...#... +...#.#. +######. +####.## + +.#..##.#.#### +###.##....##. +..#####...... +####.#....... +.##..###..##. +....#...##### +####..#.##### +#.##.##.#.... +#######...... +##.#.....#### +#.##.###..##. +#.##.###..##. +##.#.....#### +#######...... +#.##.#..#.... + +....#.#...##..... +#..#..###...###.# +#..######..##.##. +#..#.#.#...#.#..# +.......#.##...... +.##.##...####.... +.....#....####..# + +..####... +...##.... +...##.... +..####... +#.#..#.## +.#.##.#.# +..####... +########. +##...#### +#..##..## +##....### +.######.. +...##.... + +#..##.#..#..#.# +#..##.#..#..#.# +#.###...##.###. +....#.####.#.## +.##..#...#.#..# +###.#####..#.## +#.###...###.#.# +#..#.##....#.## +#..#.##....#.## +#.###...###.#.# +###.#####..#.## +.##..#...#.#..# +....#.####.#.## +#.###...##.#.#. +#..##.#..#..#.# + +.##.#..#. +####....# +#####..## +.##.####. +.##.####. +..#.#..#. +####....# +#..#.##.# +....#..#. +####.##.# +.##.#..#. +####.##.# +.##...... + +....#..##..## +....#..##..## +..###.....##. +####.##..#.#. +#..#.#.#....# +.##.#.#..#.## +.#..##..#..## +#.#.....#.#.. +###.....#.#.. +.#..##..#..## +.##.#.#..#.## +#..#.#.#....# +####.##..#.#. +..###.....##. +....#..##..## + +##.#.######.# +....##.##.##. +#####.#..#.## +##.##..##..## +...#.##..##.# +..##..####..# +..#....##.... +##.###.##.#.# +####.#....#.# + +.###.....###.## +####.#.##..#.#. +###..#.##..#.#. +.###.....###.## +#.#######.#..#. +#..#...#.#.#... +#...#.#####..#. +#...#.#####..#. +#..#...#.#.#... +#.#######.#..#. +.###.....###.## +###..#.##..#.#. +####.#.##..#.#. +.###.....###.## +.#....###.#.#.. + +..##.#....# +.######.##. +.######.##. +..##.#....# +.#.##.#.... +###.##.#### +##..#..###. +...#..#.#.# +###...#.#.# +###...#.#.# +...#..#.#.# +##..#..###. +.##.##.#### +.#.##.#.... +..##.#....# + +#..#......###.. +#..#......###.. +#.####........# +#..##.....##..# +#..#.#######..# +.##..#...#...## +.....####..#... +#..##..##.#.#.. +.##.###.#..#.## + +###.###.. +###.###.. +..#.#.#.# +####..... +..#.....# +#....##.. +###.##.## +#####..#. +#####..#. +###.#..## +#....##.. + +.###.#.##.#.###.# +##..#..##..#..### +#..##.#..#.##..## +##..#.#..#.#..##. +...###....###...# +.#...##..##...#.. +..........#...... +#....######....#. +..####.##.####... +.###.#.##.#.###.# +######.##.####### +##....#..#....### +##.#.#....#.#.##. +##.#.#....#.#.##. +##....#..#....### +######.##.####### +.###.#.##.#.###.# + +.#.#..###..## +#.##.#####... +####.#..#.#.. +.##...#.##### +#..#..###.... +#..###....... +###..#.#.##.. +..###.##.#### +..#.#.##.#### +###..#.#.##.. +#..###....... +#..#..###.... +.##...#.##### +####.#..#.#.. +#.##.#####... +.#.#..###..## +##....####### + +#.###...#.##### +######.#.####.# +#....##...##.#. +#....##...##.#. +######.#.####.# +#.###...#.##### +####..#.#..#..# +.##.###.##.##.. +....########..# +##.##..###..#.# +##.##..###..#.# +....########..# +.##.###.##.##.# +####..#.#..#..# +#.###...#.##### + +....##... +#######.. +.......#. +....#.#.. +####..#.# +#####...# +####.#..# +.....#.## +.##.#.#.. +######.#. +.....#.## +.....###. +#####..#. +####.###. +######.## + +.#...#.####.. +.#...#.####.. +..########... +.###..#.#.#.. +#...#....#.## +.......#...#. +.#.######.#.# +###.#.#.####. +....###..##.# +...#.#.####.. +...#.#.####.. +....###..##.# +###.#.#.####. +.#.######.#.# +..#....#...#. +#...#....#.## +.###..#.#.#.. + +#.#..###### +#.#.####### +.##.##....# +#.......... +###.##.##.# +.########## +##.#...##.. + +....####..### +##.###.####.# +##..#........ +##.#.#......# +..#.#.#.##.#. +....#.#....#. +..##.###..### +###.##..##..# +...##...##.#. +..#.....##... +###.##......# + +.##..#.#..#.. +#.....####### +#.#####.##... +#######..#### +.####..####.. +.####...###.. +#######..#### +#.#####.##... +#.....####### + +.#.##....##.#.... +.#.##....##.#.... +####.####.#####.. +#.##########.#.#. +.#.##....##.#..#. +####......#####.# +#...######......# +#.#.######.#.#..# +#.##.####.##.#.## +..#........#..... +#.#...##...#.#.## + +####....# +##.#....# +.######## +#..###### +#.#...... +#.####### +##..####. + +###........##.##. +###...###.#..#... +#####.#.....##### +..#.##........#.# +..#.##........#.# +#####.#.....##### +###...###.#..##.. +###........##.##. +######.###...#... +##..##.##.###.#.# +#####.#.##..#.... +...#..#..#..#.##. +...##.####..###.. +##.#....##.#....# +##.#.##.#####.### + +#...#.##. +.###.#... +.#####... +#...#.##. +.......## +#.#...### +#.#...### + +..#.##.###.##.# +.###.#.......## +#..#.#...#..#.# +########..####. +########..####. +#..#.#...#..#.# +.###.#.......## +..#.##.###.##.# +#...#...##..... +#.#..#.###..... +#..##.#.##.#### +..#######.###.# +..###########.# + +.#..##. +##.##.. +##.##.. +.#..##. +##.###. +#.##### +#..##.# +####..# +..##..# +..##..# +####... + +##..##..##..# +....######... +######..##### +##.##.##.##.# +...########.. +###.######.## +###.######.## +#####....#### +..#........#. +###........## +##.########.# +..#.#....#.#. +##...####...# +######..##### +..#.##..##.## + +#..#### +....### +####.## +.##.### +####.#. +.##.#.# +.##.#.. +....#.# +....#.# +.##.#.. +.##.#.# +######. +.##.### + +...###### +.#..###.# +####.##.# +#.#.....# +#.#.....# +####.##.# +.#..###.# +...###### +####.#### +.#..##..# +##..#.##. +.....###. +.#..#.#.. +.#..#.#.. +.....##.. + +..#..#..#.#.....# +##.##.##.#...#.#. +##.##.##.#...#.#. +..#..#..#.#.....# +.#######.#..##.## +.........###..##. +.#....#..#.#..##. + +......#..#. +..##...#.#. +#######.### +#....#.#..# +######....# +......#..#. +..##....... +##..######. +#.#####..#. +#....#.#.## +..##...#.## +..##......# +..##......# + +...#.#..# +...###### +..#...... +..####### +...#..##. +...#.#### +..#.#.##. +..##..##. +..#...##. +##.##.#.. +##....##. +..#..#..# +###..#..# + +.##.#..###.#...## +#..#.##....#.#..# +.........##.#.### +.##.....###...### +.##.##.#...###.#. +.##.##.#...###.#. +.##.....###...### +.........##.#.### +#..#.##.#..#.#..# + +#.###.##.## +#..#......# +#.#.##..##. +.###.#..#.# +.###.#..#.# +#...##..##. +#..#......# +#.###.##.## +####......# + +...##.##.#.#.#. +...##.##.#.#.#. +.##...#..##.#.# +.###.#.##..#.#. +....###..#.#### +....###..#.#### +.###.#.##..#.#. +.##...#..##.#.# +#..##.##.#.#.#. + +#..##......## +#.#....##.... +##.##.####.## +.#...##..##.. +.#.####..#### +.##...#..#... +.####.####.## +.#.##..##..## +#..##..##..## +#.#..#.##.#.. +#..#.##..##.# +#.###.####.## +##.####..#### +#.#....##.... +..#.......... + +.#.##.#.#..##.# +#..##..##...... +##....###...... +.#....#.##..##. +#.#..#.#..#.##. +#......#.#.#..# +...##...#.#.... +...##...#.#.##. +#########.#.##. +##....###...... +#.####.#..#.##. + +##..........##..# +..####..####..##. +..####..####..... +..##......##..##. +#..#..##..#..#### +#.#........#.#### +#####.########### + +###########.. +##.##.##...#. +#.#..#.##.#.# +###..######.. +#..##..##.... +#..##..##.... +###..######.. +#.#..#.##.#.# +##.##.##...#. +###########.. +.#...##.#.#.# + +..#.#.##..##. +....##.#.#.#. +#####......#. +#...#.#####.. +##..##.....## +.#.##..###.#. +..###.##..#.# +..###.##..#.# +.#.##..###.#. +##...#.....## +#...#.#####.. +#####......#. +....##.#.#.#. +..#.#.##..##. +..#.#.##..##. + +..#.#.#..#... +..#.#.#..#... +....#...####. +..##.#.#.#..# +.#.#....#.... +#####..#.#.## +.####.##..... +..######.#... +..##.#.#..### +..##...#..### +..######.#... +.####.##..... +#####..#.#.## +.#.#....#.... +..##.#.#.#..# +....#...####. +..#.#.#..#... + +.##.#.#.#.. +.##.#.#.#.. +#.####.#.#. +#.##.....## +...#.##.#.. +.##.##.#..# +...##.##.#. +#.....#.#.# +#.....###.# +...##.##.#. +.##.##.#..# + +.###..### +.##....## +#.#....#. +.######## +##.#..#.# +##......# +##..###.# +#.#.##.#. +.#......# +..#....#. +####..### +...#..#.. +...#..#.. +####..### +..#....#. diff --git a/2023/day-13/src/bin/part1.rs b/2023/day-13/src/bin/part1.rs new file mode 100644 index 0000000..3dead78 --- /dev/null +++ b/2023/day-13/src/bin/part1.rs @@ -0,0 +1,9 @@ +use color_eyre::Result; +use day_13::part1::process; + +fn main() -> Result<()> { + let file = include_str!("../../input.txt"); + let result = process(file)?; + println!("{}", result); + Ok(()) +} diff --git a/2023/day-13/src/bin/part2.rs b/2023/day-13/src/bin/part2.rs new file mode 100644 index 0000000..a2d18a2 --- /dev/null +++ b/2023/day-13/src/bin/part2.rs @@ -0,0 +1,9 @@ +use color_eyre::Result; +use day_13::part2::process; + +fn main() -> Result<()> { + let file = include_str!("../../input.txt"); + let result = process(file)?; + println!("{}", result); + Ok(()) +} diff --git a/2023/day-13/src/lib.rs b/2023/day-13/src/lib.rs new file mode 100644 index 0000000..faaf542 --- /dev/null +++ b/2023/day-13/src/lib.rs @@ -0,0 +1,2 @@ +pub mod part1; +pub mod part2; diff --git a/2023/day-13/src/part1.rs b/2023/day-13/src/part1.rs new file mode 100644 index 0000000..d4d0c54 --- /dev/null +++ b/2023/day-13/src/part1.rs @@ -0,0 +1,132 @@ +use std::iter::from_fn; + +use color_eyre::Result; +use itertools::Itertools; + +#[derive(Debug, PartialEq, Eq)] +enum Fold { + Horizontal(usize), + Vertical(usize), +} + +fn detect_fold(input: &str) -> Option { + detect_vertical_fold(input).or(detect_horizontal_fold(input)) +} + +fn detect_vertical_fold(input: &str) -> Option { + let mut columns_iter_collection = input.lines().map(|line| line.chars()).collect::>(); + let columns = from_fn(move || { + let mut items = Vec::new(); + for iter in &mut columns_iter_collection { + match iter.next() { + Some(item) => items.push(item), + None => return None, + } + } + Some(items) + }) + .collect::>(); + let result = columns + .iter() + .enumerate() + .tuple_windows() + .filter(|((_, line_a), (_, line_b))| line_a == line_b) + .find_map(|((index_a, _), (index_b, _))| { + let lines_a = (&columns[0..=index_a]).iter().rev(); + let lines_b = (&columns[index_b..]).iter(); + lines_a + .zip(lines_b) + .all(|(a, b)| a == b) + .then_some(index_a + 1) + }); + result.map(|num| Fold::Vertical(num)) +} + +fn detect_horizontal_fold(input: &str) -> Option { + let lines = input.lines().collect::>(); + let result = input + .lines() + .enumerate() + .tuple_windows() + .filter(|((_, line_a), (_, line_b))| line_a == line_b) + .find_map(|((index_a, _), (index_b, _))| { + let lines_a = (&lines[0..=index_a]).iter().rev(); + let lines_b = (&lines[index_b..]).iter(); + lines_a + .zip(lines_b) + .all(|(a, b)| a == b) + .then_some(index_a + 1) + }); + result.map(|num| Fold::Horizontal(num)) +} + +pub fn process(input: &str) -> Result { + let (horizontal, vertical) = + input + .split("\n\n") + .flat_map(detect_fold) + .fold((0, 0), |mut acc, item| match item { + Fold::Horizontal(num) => { + acc.0 += 100 * num; + acc + } + Fold::Vertical(num) => { + acc.1 += num; + acc + } + }); + Ok(horizontal + vertical) +} + +#[cfg(test)] +mod tests { + + use super::*; + + #[test] + fn test_process() -> Result<()> { + let input = "#.##..##. +..#.##.#. +##......# +##......# +..#.##.#. +..##..##. +#.#.##.#. + +#...##..# +#....#..# +..##..### +#####.##. +#####.##. +..##..### +#....#..#"; + assert_eq!(405, process(input)?); + Ok(()) + } + + #[test] + fn test_vertical() -> Result<()> { + let input = "#.##..##. +..#.##.#. +##......# +##......# +..#.##.#. +..##..##. +#.#.##.#."; + assert_eq!(Some(Fold::Vertical(5)), detect_vertical_fold(input)); + Ok(()) + } + + #[test] + fn test_horizontal() -> Result<()> { + let input = "#...##..# +#....#..# +..##..### +#####.##. +#####.##. +..##..### +#....#..#"; + assert_eq!(Some(Fold::Horizontal(4)), detect_horizontal_fold(input)); + Ok(()) + } +} diff --git a/2023/day-13/src/part2.rs b/2023/day-13/src/part2.rs new file mode 100644 index 0000000..91ef1a3 --- /dev/null +++ b/2023/day-13/src/part2.rs @@ -0,0 +1,19 @@ +use color_eyre::Result; + +pub fn process(input: &str) -> Result { + todo!("day xx - part 2"); + Ok(0) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_process() -> Result<()> { + let input = ""; + todo!("haven't built test yet"); + assert_eq!(0, process(input)?); + Ok(()) + } +}