diff --git a/input/2023/day_13/input.txt b/input/2023/day_13/input.txt new file mode 100644 index 0000000..9f4996e --- /dev/null +++ b/input/2023/day_13/input.txt @@ -0,0 +1,1319 @@ +.#.##.#.##..### +...##...####### +#.####.#.#.###. +#..##..##..#... +###..###....### +.##..##..#.#... +.#....#..###### +#..##..######## +########.#..#.. + +.#.###.###..###.# +..#...##########. +..######.#..#.### +..##.#.#......#.. +..#.##....##....# +.##..#.##.##.##.# +#.....####..####. +#.....####..####. +.##..#.##.##.##.# + +####.####.# +#..#.#..#.# +#..#.####.# +####.#..#.# +.##.##..##. +######..### +#####.##.## +#..######## +......##... +.##........ +#####....## +######..### +..#.#.##.#. +######..### +.##...##... +#..#.####.# +######..### + +.##..#.## +.##.####. +####..... +.##...##. +.##.#.### +#####..## +.##.#.##. +....#.### +####.#### +#..###..# +.#..##### +#..#.#... +.....##.. +#####.### +#####.### + +.##..##.##### +.#.##.#..#..# +##....###.##. +#......###..# +.#.##.#...... +...##.....##. +#......#...#. +.#....#...... +#......#.#### +#.#..#.#..##. +#..##..###### + +..#..#..#..##..#. +...##...#...##.## +...##...#...##.## +..#..#..#..##..#. +..#..#...##.##### +..#..#..###...### +##.##.##..##...## +#..##..##.#....## +#.....###.#.##..# +...............## +########.#......# + +..#.##....##.#. +###.########.## +#...##....##... +#####..##..#### +.#..########.## +..##.##..##.##. +.###.######.### +#.##...##...##. +#.##...##...##. + +.###.## +####..# +####..# +.###.## +..#..#. +##..... +##..#.. +..#..#. +.###.## + +#..#### +#.##### +...#... +..##... +##....# +##....# +..##... +...#... +#.##### +#..#### +.....## + +#....#.## +...##.#.# +###..#... +#....#.## +######... +..##.##.. +..#...#.# +..#...#.# +..##.##.. +######... +#....#.## +###..#... +...##.#.# +#...##.## +#...##.## + +##.###..# +##.##.##. +..##..#.. +..#..##.# +..#..##.# +..##..#.. +##.##.##. +##.###..# +......##. +.#######. +##.#.###. + +.#..... +..##### +####..# +...#### +##.#..# +#.##..# +.#.#..# +#..#### +#.##..# +..##..# +#..#### + +....#.# +#..#..# +.##..## +.##..## +#..#..# +....#.. +.##.#.# +#####.. +....##. +####... +.....## +#..##.. +.##...# +#..#... +.##...# + +..##...#.#.##.... +#.####.###.##..## +#.####.###.##..## +..#....#.#.##.... +.#..#..#....#.#.# +###..#..##.#####. +##..#..####..#.#. +..###.#..##.#.##. +...##.######..... +..#...##.#.#...#. +....#...###.#.... +....#...###.#.... +..#...##.#.#...#. + +##..##.#.## +##..##.#.## +#######..#. +.####..#... +#.##.#..#.# +.#..#.#.... +##..##.#.#. +.####...#.. +.####.#.### +..###...### +######..#.# +.####.##.#. +#.##.#.#.## +.####.##### +#######..## + +#.##...## +...####.# +####..### +###.###.# +.#.#####. +.#.#####. +###.###.# +####..### +...####.# +#.##...## +#.#.#.### +#..####.. +##.####.. + +..###.....##. +##....##..### +##....#....## +####.....#.#. +...########.. +##...#..##.#. +...#.#.###..# +######.##..#. +##....#...#.# +...#####.##.# +#####.#...##. +..#.######... +####.##...##. +###.##..#.#.. +###.##.##.#.. + +##.#...######## +.#..##.#....... +.#.#.....#.##.# +.##..#.###.##.# +#.#####.##.##.# +.##.###.#...... +.##.###.#...... +#.#####.##.##.# +.##..#.###.##.# +.#.#.....#.##.# +.#..##.#....... +##.#...######## +###.....###..## +.#.#.#.......#. +####.###..#..#. +##.##.##..####. +#.#..#..#..##.. + +#.#.....#..#... +.#####.#.##.#.# +.###.##.#..#.## +#.#.###.#..#.## +#.#####.#..#.## +.###.##.#..#.## +.#####.#.##.#.# +#.#.....#..#... +...##.##....##. + +#......#. +#.####.## +..####..# +#......#. +#......#. +..####..# +#.####.## +#......#. +########. +..#.##..# +##....##. +.#....#.. +.##..##.. + +######.##.### +..##..#####.# +.#....##.#.## +.####..##..#. +#######.#.### +#######.#.### +.####..##..#. + +.##.#..###..####. +.##.#.####..####. +#..#..#..###.#... +#..#####.###.##.# +#..###..##.####.. +#####.##...##.... +####.#.#..###..## +.##.#..#.#.#...#. +#..#..####.###..# +.##..##....#####. +.##.............# +.....########..## +#..##.##..#.###.# + +####.#..#.### +...#..##..#.. +..#######.##. +##.#.#..#.#.# +...#.#..#.#.. +##.#.#..#.#.# +#####.##.#### +##...#..#...# +......##..... +###.#.##.#.## +..###....###. +###...##...## +....######... +...#..##..#.. +##.#.####.#.# + +.##.#..##.#.#.#.. +.##.#.##.######## +.....#.####.##### +####....##..###.# +#..#..##..######. +#######.###..#..# +####...#..#.....# +.....##.#...###.. +.......##.##...#. +....#....#.#.#### +......#..##.#..#. +#..###....#...#.# +#..#...##..##.### +....#...###....## +.##....#..#.#...# +....#....#....#.. +....#....#....#.# + +..####..##### +#########..## +##.##.####.#. +########..### +##....##.#### +...##...#.... +..#..#..#.#.# +#.####.#.#.## +##....##.#... +.........##.# +..####...#.#. +...##....#... +###..####.#.. + +#..#.#..#.# +#.###.##.## +..##.####.# +.#..##..##. +#.##..##..# +.#.######## +..#..#..#.. +..#..#..#.. +.#.######## +#.##..##..# +....##..##. +..##.####.# +#.###.##.## +#..#.#..#.# +#.###....## + +#...##..##..# +...##..####.. +.#.##........ +###.#.##..##. +...##.#.##.#. +.....#..##..# +...#.#..##..# +...##.#.##.#. +###.#.##..##. + +####.######.# +.#........... +#.#.###..###. +.........#... +#............ +#..#.######.# +#..#.######.# + +####.###.## +###..#...## +###..#...#. +####.###.## +#..#....#.. +###...##.#. +.##.##..#.. +#.##.#.##.# +#..##.##.## +..#.###..## +......##.#. +..#.#.###.# +#.##.####.# +..#.####### +..........# +..........# +..#.####### + +..#.#.. +##..#.# +#...##. +..#.#.. +...#.#. +....### +#####.. +#####.. +....### + +..#..#..#.#.##.#. +..##.#..#.#.##.#. +..######.#......# +#....##.####..### +.#....#.##......# +..#.##.....#..#.. +.#.###..#.######. + +#####.#...... +.#.#.....#... +#..##.#...#.. +#.#....#..... +#....##..#.#. +##.#.####..## +#..#.#.#..... +#.####..##... +.#....##.##.. +..##...#.#.## +##..####.#.## +..#.#...#.#.. +..#.#...#.#.. + +#.##...##.. +...#....... +.###.#....# +#.#.#.#..#. +#.##.#....# +##..##.##.# +##..##.##.# +#.##.#....# +#.#.#.#..#. +.###.#....# +...#....... +#.##...##.. +..#..#....# +##...#..#.# +.###..####. +##..#.#..#. +##.#.#....# + +..##..### +######.## +##...##.. +#.##.##.. +##..###.. +.#..#.... +..##..#.. + +.###.###..##. +.###.###..##. +#.##..#...### +##..#..#...#. +#..##.##..##. +.......#..##. +##.##.##..#.# +.#.##..###.## +.#.##..###.## +##.##.##..#.# +.......#.###. +#..##.##..##. +##..#..#...#. +#.##..#...### +.###.###..##. + +.##..#..#.. +###.##..##. +###.##..##. +.##........ +##.#..##..# +..##..##..# +##.#..##..# + +....##..#.#.#.#.# +....##..#.#.#.#.# +######........### +####......###.... +.##.##.###..##### +.......#.#..#..#. +####...##.#.##.#. +#####.#..##.##..# +#..#..##.....#### +....#..#...###.## +....#....######## +.###.#...#####..# +.##.#.##.#.....## + +.#.###.#.##.# +........#...# +.#.##......## +.#.##......## +........#...# +.#.###...##.# +#.#.#.#...... +####....#.#.# +.#.....####.# +.#.#....####. +.##.#.#...##. +.#.##.##..... +..#...###..#. +###...#..##.. +###...#..##.. + +###..#... +.#.##.... +##.##.... +###..#... +#...##.## +###...... +#....#.## +.######## +...####.. + +...........#..#.# +#..####..##.#..#. +#..####..##.#.... +...........#..#.# +..#....#..#..##.. +#.#....#.##.#..## +..........#.#.... +#.#....#.#..#.#.. +.########.#.#.##. +..#.##.#...#...#. +..........#..#.## +#..####..#..#.##. +#.#....#.#.##.#.. +##.#..#.#####.##. +#..####..#.##..#. + +#.#.#.#..#. +###..###### +##.....##.. +#.##.##..## +.##..###### +..#.#.#..#. +..#.#.#..#. +.##..###### +####.##..## +##.....##.. +###..###### +#.#.#.#..#. +..##..####. + +#..#.#.#. +#..#.#.#. +..#.#..#. +.#..#.... +..####### +..####### +.#..#.#.. +..#.#..#. +#..#.#.#. + +##..###...# +#....##.#.. +..##..##### +..##..#.#.# +#.##.####.. +######....# +.#..#...#.# +#....#.##.# +.#..#....## +.#..#....## +#....#..#.# + +...##.##. +..#..##.# +#.###.### +#.###.#.# +.#.#...## +##...#... +##..##.## +##..##.## +##...#... +.#.#...## +#.###.#.# +#.###.### +..#..##.# +....#.##. +....#.##. + +#....##.# +#....#### +##..##.## +#.##.#..# +#....##.. +.#..#..## +#.##.#.## +##...#### +#.##.#.## +#.##.#.## +##...#### +#.##.#.## +.#..#..## +#....##.. +#.##.#..# +##..##.## +#....#### + +#..#....##.##.# +....##..#..#.#. +....##..#..#.#. +#..#....##.##.# +#.######.#.##.# +#......##.#..## +....###...##### +##...#.#...##.. +.#.......##..## +.#.......##..## +##..##.#...##.. +....###...##### +#......##.#..## +#.######.#.##.# +#..#....##.##.# + +#...##...#..# +#.####.#.#### +..#...#..#..# +#...#.#.##..# +#..#..###.##. +...#....#.... +.###..#.##..# +..##.#....... +..##.#....... +.###..#..#..# +...#....#.... + +##..##.#.#. +.#.#.#.###. +####.##.#.# +#######.#.# +.#.#.#.###. +##..##.#.#. +#.....#.#.# +#.....#.#.# +##..##.#.#. +.#.#.#.###. +#######.#.# + +......# +.###### +.#..#.. +.#..#.# +.####.# +......# +##..##. +#....#. +#.##.## +#.##.## +#....#. +##..##. +......# + +#.#.######. +.#.##....## +####......# +...#.#..#.# +##...#..#.. +.#..######. +#.#..#..#.. +..#....#... +.##..####.. +#.##.#..#.# +#.###....## +..#........ +..#........ + +.####.####.## +#.##.#....#.# +.####......## +.####..##..## +#....#....#.. +..##...##...# +.......##.... +.#..#..#...#. +..##........# +.#..#..##..#. +#....##..##.. +..##..####..# +.####.#..#.## +......#..#... +##..###..###. + +.#..##.#.#.#..#.# +##.#.....#......# +#.#..#.##.##..##. +....#...###.##.## +.......#.##.##.## +.......#.##.##.## +....##..###.##.## +#.#..#.##.##..##. +##.#.....#......# +.#..##.#.#.#..#.# +#...###...#.##.#. +.#.####..#.#..#.# +######...##.##.## + +####....#####.# +####....#####.# +#.###..###.###. +#..........##.. +#..#.##....#..# +####.##.####### +#..#.##.#..##.. +.##......##.#.. +###..##..###..# + +......##.## +####.##.### +#..#####... +.##.#.#.##. +.##.#.#.##. +#..#####... +####.##.### +.....###.## +#..#...##.# +.##..##.#.. +####....#.. + +#..#..#.###.####. +###.##...##.....# +##.#........#..#. +.....##..###.##.# +..#...#.##..#..#. +.#....#######..## +......##.....##.. +#..###.########## +.#..####.###....# +..#..##.#####..## +.##.#.###.#.####. +#.##..#..#....... +.....##..##.#..#. +.###...###..#..#. +.###...###..#..#. + +.####..##..#### +...###....###.. +#.#.##.##.##.#. +....#.#..#.#... +#....######.... +#......##...... +....#.#..#.#... + +......####..### +.#..#.#####.### +#.##.#......... +#.##.###.#..#.# +.####..###..### +######..######. +..##......##... +##########..### +.......#......# +.#..#..##....## +......##.####.# +##..###........ +......###....## +.####....####.. +#.##.#..#....#. + +#####.# +#.##..# +##.#.#. +###..#. +...#.#. +###.### +..##### +..##### +###.### + +##.###. +###...# +##..... +..#...# +##.##.# +..#.### +..#..## +......# +......# +..#..## +..#.### +##..#.# +..#...# +##..... +###...# +##.###. +...###. + +..##.###.#...## +#.##.###.....## +#.##.###.....## +...#.###.#...## +.#....#...#.#.. +..####..#####.. +...######.##.## +.#.#..#.#.##### +.#...#..#...... +.#...##..###### +.#..#.####..#.. + +#.##.#..# +#.##.#..# +..#.##### +##.##.##. +#.#.##.## +.###..... +...##.... + +....#..#....### +##.#...##.#.### +###...#....#.## +..##.#...###### +######.####.### +.........##.... +#.##..######... + +....##. +#####.# +....#.. +....##. +#..##.. +.....#. +#####.# +#####.# +.....#. +#..##.. +....### +....#.. +#####.# + +.##..#..# +#.###.### +.#..##..# +##.####.. +.#..##... +......#.. +......#.. +.#..##... +##.####.. +.##.##..# +#.###.### +.##..#..# +....#..## +...###... +.#..###.# +.#..###.# +...###... + +.#....#.##... +#......#.#.## +#.####.###... +##########... +.##..##...... +.#....#...### +.##..##.##.## +.##.###..##.. +########.#### +..####..##.## +...##...#..## +.##..##...#.. +#.####.#..### +##....###.### +.#....#.###.. + +#..#####.#..# +###.##.###### +#........#### +.#.#..#.#.... +..........##. +#........#..# +##..##..##### +#..#..#..#..# +#.######.#..# + +.#..#.####.#..# +...#...##...#.. +#...##....##... +##..##.##.##..# +##..##.##.##..# +#...##....##... +...#...##...#.. +.#..#.####.#..# +##.#........#.# +.##.#.####.#.## +###..........## +.##.########.## +.#..##.##.##... +...#.#.##.#.#.. +.....#.##.#.... +###.#......#.## +#.###.#..#.###. + +#..#.#.## +....##.#. +....##.#. +#..#...## +.##.#..## +.....#.## +.##...#.# +#..#....# +....####. + +#####..##.# +#.#.#.#.#.. +###.##.##.. +##.##.#...# +...#..#.##. +...#..#.##. +##.##.....# +###.##.##.. +#.#.#.#.#.. +#####..##.# +####..#.#.# +####..#.#.# +#####..##.# +#.#.#.#.#.. +###.##.##.. + +##.##.######. +.######.##.## +##.##.######. +..#..#......# +.#..#.#.##.#. +#.#..#.#..#.# +###..######## + +.#.#.#..##..#.#.# +.###...#..#...### +#..#.#..##..#.#.. +.#.#...####...#.# +#.#....#.......#. +#................ +...#.#......#.#.. +..#.####..####.#. +...#...####...#.. +#.#.##..##..##.#. +.....#.####.#.... +#.##.#.####.#.##. +.###..#....#..### +.##..########..## +.##..########..## +.###..#....#..### +#.##.#.####.#.##. + +#..#.#..#.# +..###.##..# +#..#......# +###.######. +#.##.####.# +#.....##... +#...#....#. +..#..#..#.. +#.#........ +.###..##..# +.###..##..# +#.#........ +..#..#..#.. +#...#....#. +#.....##... + +..####..##. +#.##....... +###.....##. +.###.#..##. +#...#...... +#.###..#### +##..#.##### +.#..#.##### +#.###..#### + +......##### +####.##.##. +####.#..... +######...#. +....###.### +.##.##.#### +.##..#.#### +....###.### +######...#. +####.#..... +####.##.##. +......##### +#..#.##.### +####.#..#.. +#..####.### + +..##.##.##..##..# +..#.####.#..#.### +#####..#####..### +.#.##..##.#...#.# +.#.##..##.#...#.# +#####..#####..### +..#.####.#..#.### +..##.##.##..##..# +##..####..##.#..# +#...#..#...#..#.. +##..#..##.##.#... + +...##..##...#.. +##.####.##.#.## +...#.##.#####.. +..#.####..#..## +..#########..#. +..#########..#. +..#.####..#..#. +...#.##.#####.. +##.####.##.#.## +...##..##...#.. +########...###. + +####.#####. +...###....# +...#.....## +...#.....## +...###....# +####.#####. +#....##.##. +.....#.#..# +.##..#..... +.##..##.... +.....#.#..# +#....##.##. +####.#####. +...###....# +...#.....## + +####....##.#### +.....##.#..###. +##.##.#####.... +##..###......## +#.#..####.#.#.# +##..#.####.#... +##..#.####.#... +#.#..####.#.#.# +##..###......## +##.##.#####.... +.....##.#..###. +####....##.#### +.#..####.##.### +#.#.####..###.# +#.######..###.# + +.#.#..#.#.#.##.#. +.#.#..#.#.####.#. +...#..#.....###.# +####..######.##.. +..........#.#..#. +..##..##..#...##. +.###..###.##.#..# +...####...#.#..#. +.#.####.#.###.#.. +#.#.##.#.###.#.#. +.#.#..#.#.#..##.. + +###..###. +###...##. +..##.##.# +.#..####. +#..##.#.. +.#.##.#.. +.....#.#. +.....#.## +#.#.##.## +#.#.##.## +.....#.## +.....#.#. +.#.##.#.. +#..##.#.. +.#..####. + +..#............#. +..##.###..###.##. +..##.##.##.##.##. +##.#####..#####.# +..##.##....##.##. +.....#..##..#.... +###.#.##..##.#.## +##.#.###..###.#.# +...#..##..##..#.. +..#.#........#.#. +#######.######### + +###.....#.#.##. +..#..##.#.##..# +####.....###.## +..#.....#...#.# +..#.#...#.###.# +##.#..####.#..# +..#.#.#.###..#. +##.##..##..#.#. +##.##.###..#.#. + +....#..#. +####....# +.##...... +#.##.##.# +#..##..## +#..##..## +#####..## + +.#.#.## +####... +###.... +..#.#.. +..#.... +###.... +####... +.#.#.## +#.##... +.#.##.. +..#..## +#....## +...#.## +.#...## +.###... + +###..###..#.#.. +.######..##.### +##########...## +..####..##.#... +#.#..#.###.###. +.##..#..#...##. +##.##.##.#..#.. +##.##.###..##.. +###..####.#.#.# +###..####.#.#.# +##.##.###..##.. + +#.####.## +.##..##.# +#####.### +..#..#... +##....##. +.######.# +#..##..#. +#.####.## +..#..#..# +...##.... +..####... +..#..#..# +..#..#..# +..####... +...##.... +..#..#..# +#.####.## + +.#.##..#.#..... +..#.###.#####.. +..#...#.#.##... +##.##..#.#..### +...#..##.###.#. +..##.#######.## +..##.#######.## +...#..##.###.#. +##.##..#.#..### +..#...#.#.##... +..#.###.#####.. + +#.######### +.#.#.#..#.# +#.###.....# +##..#.##.#. +.#..#.##.#. +.###.#..#.# +#...#.##.#. +#...##..##. +.#....##... +#.#.#....#. +#.#.#....#. + +#..#..#.# +#..#..#.# +..#....#. +##..##.#. +#.#.##.## +.##...##. +##.###... +#.####... +######... +##.###... +.##...##. +#.#.##.## +##..##.#. +..#....#. +#..#..#.# + +#....#..# +#.##.#... +##..##... +##..##... +#.##.#..# +#....#..# +.####..#. +.#..#...# +##..##### + +#...##...#....##. +..#.##.#..###.... +..##..##..##.#### +...####.....##..# +#.######.#....### +###.##.####..#..# +##..##..##.##.##. +#........##.##### +...........#.#..# + +.#.#..#..#.## +.##.#...##### +.##.#...##### +.#.#..#..#### +#..#.....#... +.####.##.#... +..#..###.#... +#.##.##...... +########.#### +#####..##.### +#....#..#..## +..####...#.## +..#.#.##.#.## +...#.#.#..... +#.#..#.##.... +##.#.#.#..#.. +#.#####.#.#.. + +##.##.##.##.# +##.###..###.# +.####.##.#### +#####.##.#### +##.##.##.#..# +#.#........#. +#.#........#. + +####.#.#.#..# +.##.#.##.#..# +.##...###.##. +.##..##.##..# +.....###.#..# +....#.#..#### +######..#.##. +......##..... +####.#.#.#..# +.##..##..#### +.##....#..... +#####..#..... +#...##..#.... +.##..######## +.##.#...##### +#..######.... +.....##..#..# + +###....## +..#.##.#. +..#..#.#. +....##... +##......# +...#..#.. +###....## +..######. +..##..##. + +##..##.###### +.####.####### +.####.##.##.# +.#..#..#.##.# +######.#....# +......#..##.. +######.##..## +.#..#...###.. +#....#....... +#######.#..#. +..##....#..#. +#....###....# +########.##.# + +#..#.##.#.. +#..#.##.#.. +#..#.#.##.. +#.#####.##. +####...#### +#..######.# +.##.###..## +#####.#.##. +....###..#. + +#..###.#. +...#...## +##...##.. +###.###.. +##...#.## +...###.## +...#.#.## +##...#.## +###.###.. +##...##.. +...#...## +#..###.#. +#..###.#. + +####.####..## +#.......#...# +#.#......##.# +#..##...#.### +#..##...#.### +#.#......##.# +#.......#...# +####.####..## +#.##..####### +....#..##.##. +..#...#...### +##.####.##### +##..###.##### + +###.#.# +##...## +#..##.# +##.#.## +..##... +..#.##. +#####.. +#####.. +..#.##. \ No newline at end of file diff --git a/input/2023/day_13/input_test.txt b/input/2023/day_13/input_test.txt new file mode 100644 index 0000000..f226414 --- /dev/null +++ b/input/2023/day_13/input_test.txt @@ -0,0 +1,15 @@ +#.##..##. +..#.##.#. +##......# +##......# +..#.##.#. +..##..##. +#.#.##.#. + +#...##..# +#....#..# +..##..### +#####.##. +#####.##. +..##..### +#....#..# \ No newline at end of file diff --git a/src/year_2023/day_13_point_of_incidence/mod.rs b/src/year_2023/day_13_point_of_incidence/mod.rs new file mode 100644 index 0000000..4124ada --- /dev/null +++ b/src/year_2023/day_13_point_of_incidence/mod.rs @@ -0,0 +1,25 @@ +pub mod part_one; +// pub mod part_two; +// pub mod common; + +use crate::utils::solution::Solution; +use crate::utils::input_reader; + +pub struct DaySolution ; + + +impl Solution for DaySolution { + + fn input_path(&self) -> &'static str { + "input/2023/day_13/input.txt" + } + + fn part_one(&self) -> String { + input_reader::read_input_file(self.input_path(), part_one::part_one) + } + + fn part_two(&self) -> String { + // input_reader::read_input_file(self.input_path(), part_two::part_two) + String::from("Not implemented") + } +} \ No newline at end of file diff --git a/src/year_2023/day_13_point_of_incidence/part_one.rs b/src/year_2023/day_13_point_of_incidence/part_one.rs new file mode 100644 index 0000000..465185a --- /dev/null +++ b/src/year_2023/day_13_point_of_incidence/part_one.rs @@ -0,0 +1,138 @@ +pub fn part_one(input_lines: Vec) -> String { + + let mut patterns: Vec>> = Vec::new(); + let mut acc: Vec> = Vec::new(); + + for line in input_lines { + if line.is_empty() && !acc.is_empty() { + patterns.push(acc.clone()); + acc = Vec::new(); + continue; + } + + let mut line_vec: Vec = Vec::new(); + for c in line.chars() { + if c == '#' { + line_vec.push(true); + } else { + line_vec.push(false); + } + } + acc.push(line_vec); + } + + if !acc.is_empty() { + patterns.push(acc); + } + + let mut result = 0; + + // println!("Found {} patterns", patterns.len()); + + for pattern in patterns { + let val = process_pattern(&pattern); + result += val; + } + + result.to_string() + // String::from("Not implemented") +} + +fn find_same_rows(pattern: &Vec>) -> Vec { + let mut res: Vec = Vec::new(); + for i in 1..pattern.len() { + if pattern[i] == pattern[i-1] { + res.push(i); + } + } + + res +} + +fn find_same_cols(pattern: &Vec>) -> Vec { + let mut res: Vec = Vec::new(); + for i in 1..pattern[0].len() { + let col_i: Vec = pattern.iter().map(|x| x[i]).collect(); + let col_j: Vec = pattern.iter().map(|x| x[i-1]).collect(); + + if col_i == col_j { + res.push(i) + } + } + res +} + +fn validate_row_pattern(pattern: &Vec>, mirror_idx: usize) -> bool { + + + let mut i = mirror_idx - 1; + let mut j = mirror_idx; + + while j < pattern.len() { + + if pattern[i] != pattern[j] { + return false; + } + + if i == 0 { + break; + } + + i -= 1; + j += 1; + } + + true +} + +fn validate_col_pattern(pattern: &Vec>, mirror_idx: usize) -> bool { + + let mut i = mirror_idx - 1; + let mut j = mirror_idx; + + while j < pattern[0].len() { + let col_i: Vec = pattern.iter().map(|x| x[i]).collect(); + let col_j: Vec = pattern.iter().map(|x| x[j]).collect(); + + if col_i != col_j { + return false; + } + + if i == 0 { + break; + } + + i -= 1; + j += 1; + } + + true +} + +fn process_pattern(pattern: &Vec>) -> usize { + + let mut mirror_indexes = find_same_rows(&pattern); + + if !mirror_indexes.is_empty() { + + for mirror_idx in mirror_indexes { + if validate_row_pattern(&pattern, mirror_idx) { + return 100 * mirror_idx + } + } + } + + mirror_indexes = find_same_cols(&pattern); + + if !mirror_indexes.is_empty() { + + for mirror_idx in mirror_indexes { + if validate_col_pattern(&pattern, mirror_idx) { + return mirror_idx + } + } + } + + panic!("Invalid pattern"); + +} \ No newline at end of file diff --git a/src/year_2023/mod.rs b/src/year_2023/mod.rs index e7b87e5..c1b9dba 100644 --- a/src/year_2023/mod.rs +++ b/src/year_2023/mod.rs @@ -10,6 +10,7 @@ pub mod day_09_mirage_maintenance; pub mod day_10_pipe_maze; pub mod day_11_cosmic_expantion; pub mod day_12_hot_springs; +pub mod day_13_point_of_incidence; pub fn run(day: &str) { let solution: Box = match day { @@ -23,6 +24,7 @@ pub fn run(day: &str) { "10" => Box::new(day_10_pipe_maze::DaySolution), "11" => Box::new(day_11_cosmic_expantion::DaySolution), "12" => Box::new(day_12_hot_springs::DaySolution), + "13" => Box::new(day_13_point_of_incidence::DaySolution), _ => panic!("Invalid day specified"), };