diff --git a/advent-of-code-2023.csproj b/advent-of-code-2023.csproj index a384cb0..48a4fb0 100644 --- a/advent-of-code-2023.csproj +++ b/advent-of-code-2023.csproj @@ -54,6 +54,8 @@ + + diff --git a/inputs/13.txt b/inputs/13.txt new file mode 100644 index 0000000..09ca5ce --- /dev/null +++ b/inputs/13.txt @@ -0,0 +1,1311 @@ +.##.###..####.. +....#..#.####.# +.##.###...##... +.##..###..##..# +.##..##..#..#.. +####.#####..### +####.##..####.. +#..###..#.##.#. +#..#....##..##. +...#.#.###..### +......#.#.##.#. +.....##...##... +#####...##..##. + +....#.#..#. +####.##.### +##.##..#### +..#.#.#.... +#...#.###.# +..#.###.### +..#.###.### +....#.###.# +..#.#.#.... +.#.#....##. +.#.#....##. +..#.#.#.... +....#.###.# +..#.###.### +..#.###.### +#...#.###.# +..#.#.#.... + +......########... +....#..#.##.#..#. +##....########... +###..#.#.##.#.#.. +...#....####....# +#####.########.## +..#....##..##.... +###....#.##.#.... +##.#.#..#..#..#.# +###.....####..... +###.#.##....##.#. +###.#####..#####. +...#...#.##.#...# +..#####......#### +..#.####.##.####. +......#.#.##.#... +..#.####.##.####. + +##.#.##.#.# +.###.##.### +.###.##.### +##.#.##.#.# +.########## +.########## +...##..##.. +..#.####.#. +###..##..## +###..##..## +##.##..##.# +##..#.....# +..#.####.#. +..#.#..#.#. +#..#.##.#.. +#.#.####.#. +##..#..#..# + +#.#..#.#. +#...##### +.#..##..# +##..#.#.# +..##.###. +..##.###. +##..#.#.# +.#..##..# +##..##### +#.#..#.#. +.###.#.#. +###.#...# +..#.#.#.. +...##.#.. +...##.#.. + +.######## +####.##.# +#.##..#.# +....#..#. +.#.##..## +#.###..## +...##..## +####.##.# +#....##.. +###...... +.#..####. +.####..## +.####..## +.#..####. +###...... +#....##.. +####.##.# + +..##..##..#.# +..##..##..#.# +##...####...# +#.......#..## +.#..##.#.#.#. +#.##.......#. +..#.#...##... +#.#..#.##..#. +#.#..#.##..#. +..#.#...##... +#.##.......#. +.#..##.#.#.#. +#.......#..## +##...####..## +..##..##..#.# + +##########. +###.##.#### +..######... +.##....##.. +##......### +###....#### +..#.##.#..# + +####.####.####### +...##.##.##...... +.############.#.. +###.##..##.###... +.#.#..##..#.#.#.. +##...####...###.. +#....#..#....##.. +....#....#....### +.#..#.##.#..#..## +...###..#.#...#.. +#..#......#..#.## + +..##...#.## +..##...#.## +....#.##..# +#...###.### +...##.##.#. +.####....#. +.#.#...#.#. +.#.###.#.#. +.#.###.#.#. +.#.#...#.#. +.####....#. +...##.##.#. +#...###.### +....#.##..# +..#....#.## + +...#####..# +.#...##...# +.##...#...# +##.#......# +..#..##.##. +..##.##.##. +##.#......# +##.#......# +..##.##.##. +..#..##.##. +##.#......# + +###..#.#. +##...#.#. +......#.. +##..#.### +##.###.## +..####.#. +....#.##. +....##.#. +#....#... +##..##.## +##..##.## +#....#... +....##.#. +....#.##. +..####.#. + +.####..#..#.. +.####........ +#.##.#..##..# +#######..#.## +##..##......# +######.####.# +.####..####.. + +#..###..##..### +#..##..####..## +.....###..####. +######..##..### +....#........#. +#####.#....#.## +#..#.#.####.#.# + +#..###...#.#..#.# +#..###...#.#..#.# +##...##.#.#.##### +#.####........#.. +##..#..#..#...#.. +.###.##..#####.## +....#..###..#.#.# +..###...#........ +..###.#.#........ +....#..###..#.#.# +.###.##..#####.## +##..#..#..#...#.. +#.####........#.. + +#..#..# +..###.# +..####. +###.#.# +.###..# +.###### +###.... +###.... +.###.## +.###..# +###.#.# +..####. +..###.# +#..#..# +#..#.#. +#...##. +#...##. + +.....###..... +##..#..#..### +.###.##.###.. +#..######..## +.##.#..#.##.. +.##......##.. +.###....###.. +##..#..#..### +.##.#..#.##.. + +.....###..#.. +#.#...#.#..## +#####.##.#### +#..#..##.#### +#...#####.### +##.###.###.## +.#.###....#.. +.#.###....... +##.###.###.## + +...#.#....# +..######### +###.####### +##..###..#. +..#.####### +##....####. +..#..#....# +###..##..## +....####### +##.###....# +#######..## +...###....# +##..####### +###..#.##.# +##....#..#. + +..##..####..###.. +######...##..##.# +######...##..#..# +..##..####..###.. +######.##...####. +..##...###..#.... +#.##.##.####..... +........#######.. +.#..#.#...#...#.. +#....##..##...### +##..##..###.##.#. +#....###.####.... +.#..#.#.###.#...# + +#....##..#... +.##.......#.. +##.##..##..## +.#.##..##..## +.##.......#.. +#....##..#... +#...###.###.. + +.#....#.. +##.##.### +##.##.### +.#....#.. +.######.# +##.##.### +........# +##.#..##. +.######.# + +.......##.####.## +......#.##.##.##. +.#..#.#.#.....##. +##..#####..#.#..# +#.##.#.#.##.#.... +..##...###.#.#..# +......#..#....... +.####....##...... +.......##.##.#### +.#..#.##.###..##. +########..###.##. + +.....####.... +#####....#### +##..##..##..# +#.##......##. +#.##########. +..##..##..##. +#.##..##..##. +.####.##.#### +##..#.##.#..# + +#...#.####. +..##.###..# +#.#.##..... +########..# +..#..###..# +#....##.... +##..#..#..# +#..####.... +#..####.... +##..#..#..# +#....##.... +..#..###..# +########..# + +##..#......#.#..# +#...#......#.#..# +..#.#.#.##..#.... +###.###.##...#### +#..##.#...#.#.##. +#.####..##.#.#### +...#.#...#.##.##. +#.####.###..##..# +##..#..##.....##. +####.....##.##..# +.#.....##.###.... + +###..#######. +.##..##.###.# +##.##.##.#.#. +##.##.##.#.#. +.##..##.###.# +###..#######. +#......#..#.# +..####.##...# +#.####.####.. +.#.##.#.##... +#.#..#.#...## +#......#####. +##########.#. + +.#..#.##..# +######.#..# +......###.# +#....###..# +.#..#.#.#.. +.........#. +###.######. +#....#.#.## +......#.### +######.#... +#....#.##.. +#....#.##.. +######.#... +......#.### +#....#.#.## + +....##......##. +..#..##.##.##.. +###..#.####.#.. +...##.#....#.## +.#...#.####.#.. +#####...##...## +..#...#....#... +#######.##.#### +##.#####..##### +....#...##...#. +###.#.#.##.#.#. +..#.##########. +...#..........# +..#...######... +####...#..#...# + +#.#.##..#.. +#.....#.### +#####.##.## +#.####..... +##..###.... +#...#...#.. +##...###.#. +.#.######.. +.#.######.. + +##.#.#..# +..#.##.## +#....#### +##.##.#.. +.##...### +.##...##. +##.##.#.. +#....#### +..#.##.## +##.#.#..# +.#..##.## +.#..##.## +##.#.#..# +..#.##.## +#....#### + +.##.###........#. +##.#.##...#.##### +.#..#.###.#####.# +.#..#.###.#####.# +##.#.##..##.##### +.##.###........#. +##.##..#....#.### +#...#....######## +.###.#..###.....# +.###.#..###.....# +#...#....######## +##.##..#....#.### +.##.###........#. + +#.#....#.##.### +...#..#...#.### +..........##### +##########..... +#.#.##.#.#..#.. +......#...#.### +.#......#...... +#..####..#.#... +....##....##.## +#.######.#..### +##.#..#.###..## +##......##.##.. +.##....##.##.## + +#.###.### +#.###.### +.##.##### +###.##..# +..##.#.## +.###.#.## +..#.#.#.# +.#.#...#. +#..###.#. +#..###.#. +.#.#...#. +..#.#.#.# +.###.#.## +..##.#.## +###.##..# +.##.##### +#####.### + +......#.#..###. +###..####....#. +####..###.###.. +###.######..... +#######.#.##... +#######.#.##... +###.######..... +####..###.###.. +###..####....#. +......#.#..###. +#####...#####.# +.#.###.#..#.### +###..###...#... +..##....##..... +###.##..##.#.#. +####...##.#.#.# +####..#.#.###.. + +...##...... +..#....##.. +###..###### +#.#.##....# +..###.#..#. +....#.####. +######.##.# + +#..##....###. +#..##....###. +#....#.###... +.####.##.#.## +.####..#...## +####.#...#... +.###...#.#... +.###...#.#.#. +####.#...#... +.####..#...## +.####.##.#.## + +..##..#.##...#.## +....##....#..#... +....##....#..#... +.###..#.##...#.## +####.....#.....## +#.##...##.##.##.. +.###.....####.### +#.#...###.##.##.. +#.....###.#####.. +##.##.#..#.#...## +.#####.##..#...## +.####.#.#....#### +.#.#.##.#.####... +..#..##...#.##### +.####...##..##... + +##..#.# +##..#.# +...###. +##.#.## +.#..### +..#..## +......# + +..##.## +##..### +.###..# +####.## +#.##.## +#.#...# +#.##### +###.... +#...... +.#.###. +.#.###. +#...... +###.... +#.##### +#.#...# +#.##.## +####.## + +#.####.#..###.##. +.#....#.#.#.##..# +##....##.##.##..# +.#....#.#.##..##. +###########..#..# +.#....#..#..##### +..#..#....###.##. +.#.##.#..#...#..# +#..##..##.##.#### +##....#####.##### +.###.##....##.... + +.####...##....# +#.##.##.##....# +########..####. +######.#..####. +.####...#...... +..##..#........ +#########...... +.####..###....# +#....#####...## +#....#.#.##..## +..##....#.####. +..##...######## +######...##..## +.####.#.#.#..#. +.#..#...#...... + +.#..#.#..## +.#..#.#..## +..####..... +##.....##.. +..#.#....#. +..####.###. +....#.##..# +##.#..###.# +##.#..###.# +....#.##..# +..####.###. +..#.#....## +##.....##.. +..####..... +.#..#.#..## + +#######..#...## +....#.#.#.###.# +##.....##...... +##.....##...... +....#.#.#.###.# +#######..#...## +#.##.#.###.###. +##..#.##.....#. +.#.##...####... +###.###..##..## +..##.....#..... +..##.....#..... +###.###..#...## + +.#.###.###### +.....#..#.#.. +#..#.##...... +..##.####.### +#.#...##...## +..#.###..#### +##.#.#..##... +.##.#.##.#.## +..###.#.#.#.. +.#.#.#.###.## +##.###..##... +##.###..##... +.#...#.###.## + +###..#####.##.### +..###.#####..#### +###....#.##..##.# +##.####..######.. +..#.#..##.#..#.## +##..###..#....#.. +###.##...######.. +....#..###....### +##..##.####..#### +##.#.#...#.##.#.. +..#.#####..##..## +#####.....#..#... +#######.##.##.##. +.....#.##.#..#.## +###..#.#.######## +..#..######..#### +##.##.....####... + +..#........ +#..#..##..# +####..##..# +..###....## +..###....## +####..##..# +...#..##..# +..#........ +#.##..##..# +...#.####.# +.#.#.#..#.# + +###.#.####. +.##.####### +.####.####. +###.#...... +##...#.##.# +.#.###....# +.####.#.... +#....##..## +.##....##.. +##.###....# +.#.#..#..#. +.##.#.#..#. +#.#..#.##.# +#.#####..## +.#.#.###### +#..####..## +#..####..## + +####.##.#.### +##.##.#.##### +###..#.#.#..# +##..#..#.#### +...#.##.##### +...#...#..... +..#.##.#..... +..###.#.##..# +##.#######..# + +.#.#.###### +.#....##..# +.##..#.#..# +.#####..##. +###.#..#### +...##.#.... +.#..##..... +.#..##..... +...##.#.... +###.#..#### +.######.##. +.##..#.#..# +.#....##..# + +####..##..# +.##........ +.##..####.. +####.....## +#####.##.## +.....#..#.. +....#....#. + +..#..#. +....#.# +##.##.# +##...## +...#... +##..##. +##.###. + +.####..#.#.##...# +.####.##.#..#...# +.####.#.....##..# +..##...#####...#. +#.##.#.###..##... +.####.#.#.##.###. +##..###..#...#... +.####.#....##.### +.####.#...###.### + +...#..##### +.....#..#.# +#.###..#.## +#.###..#.## +.....#..#.# +...#..##### +#.#...#.##. +#.#.#.##.## +#..#.##.... +.##...##..# +..#...##..# + +..####.##.# +...###.##.# +.#..##.##.# +.###.##..## +...#.#....# +#.#...####. +...#....... +.#.##.#..#. +#....#.##.# +#....###### +...#....... + +#..##...####...## +..#...###...##... +.#.#.##..##..##.# +..#...#..##..#... +..#.#.##.##.##.#. +.###.##.####.##.# +......#..##..#... +##.#.#..####..#.# +##.#.#..####..#.# + +##..###..#..#.# +.####.#.#.#..## +..##..###.#.### +#.##.#.....###. +#.##.#.....###. +..##..###.#.### +.####.#.###..## + +...#.######.##.## +...#.######.##.## +#..##.....####.#. +..#######..####.. +#....####.#.##.#. +..##..#.####..### +##...#.#.##.##.## +.#.#..#.....##... +##..##.##..#..#.. +###.#..##.#.##.#. +####..#.##......# +.######..######## +###.#.###.##..##. + +..##.###..#.#.. +#..#......###.. +.#.########.... +.#.########.... +#..#......###.. +..#..###..#.#.. +.#.##.#.#.#.... +.##.###..##..## +.#...##.###..## +.##.#.###.#.... +.####..#.#..### +#..#######..### +..##..#......## + +#.#..###....### +.........#.#.## +.#....###....## +#....###..#.... +#....###..#.... +.#....###....## +.........#.#.## +#.#..###....### +..#.#..#.##.... +#.#..##..#..#.# +...#...#......# +#.#..#.#####.## +#.#..#.######## + +.#.#.#...#. +.#.#.#...## +.#.#.#...## +.#.#.#...#. +#.#..###.## +####.#....# +##.##.#..## +#...#####.# +#..##...#.# +#.###...#.# +.#.#....### +###..#..#.# +#.......#.. +.##.#####.# +##.##....#. + +######..########. +....##..###..###. +#..#..####.##.### +.....#.#.#.##.#.# +#..##...##....##. +..........####... +#..##.###..##..## +.......#..####..# +.....#....####... +#..###.#..####..# +####..#####..###. +#####..###....### +#..#.##.########. + +.#..#......#. +#####.#..#.## +#####.#..#.## +.#..#......#. +###.##....##. +###..#....#.. +#.#..######.. +..###.####.## +#...########. +###.#......#. +#.########### +##.#.######.# +.#..##....##. +..#.##.#####. +##.#.#....#.# +##.##..##..## +###.###..###. + +##.####...... +..#...#.#.##. +##.#..##.#.## +##..####..##. +.....###..... +##..##.#..##. +..##....#.... +##.##...##### +..###.#.#.##. + +####.#### +..##.#### +##..#.##. +#####.... +#..#.#### +#..#.#### +#####.... +##..#.##. +.###.#### + +#.##.#.###.## +#.##.#.###.## +##..##..##### +.####.##.##.# +.###...###..# +.#..#..#..### +..##...##.### +#....#..###.# +.#..#.......# +..##..##..### +#....##.###.# +#....#.#..... +.####.##.###. +.####..####.# +..##..#.##... + +....##########... +.##.##......##.## +...####.##.####.. +####.########.### +#.#####.##.#####. +#..##.######.##.. +###.#..#..#..#.## + +.##.##.##.#.#...# +....##.....###..# +#.##..##.#.##..## +...#..#...#.###.. +#...##...###..... +#...##...####.... +...#..#...#.###.. + +.###.#. +####.## +####.## +.###.#. +.....## +###.### +.#..### +#.#...# +.##..## +..##.#. +..#.#.# +..#...# +..##.#. +.##..## +#.#...# + +########..##. +###.#....#... +...#.###.##.# +...#.###.##.# +###.#...##... +########..##. +.....#..#..#. +....#.#..#### +##....####.## +###...#...##. +##.####.#.#.# +##.###.##.##. +....#.###.##. +......###.#.# +..######..#.. +...#..####..# +######.#.##.. + +.####.#...##.#. +..##....#####.. +#.##.##..#####. +##..###.#.###.# +.####.#.#...... +#.##.###..#...# +#.##.###..#...# +.####.#.#...... +##..###.#.###.# +#.##.##..###### +..##....#####.. + +##..##.#.......#. +..#.##...#.#...## +#..###..##.#.#..# +.#.#...####.##..# +##.#..#..##....#. +...#.#######..### +.#.##......##..#. +.#.##......##..## +...#.#######..### +...#.#######..### +.#.##......##..## +.#.##......##..#. +...#.#######..### + +.......#.##.# +##..##.###..# +.........#..# +#.##.#..####. +#######...... +#.##.####...# +#.##.#####..# + +.####.##.## +.##..#####. +....#.##... +....#.##... +.##..#####. +.####.##.## +###.#####.. +...#.#..#.. +.#....###.. +.##...#.### +##......### +##......### +.##...#..## + +###.#.#.# +#.##.##.# +#.##.##.# +###.#...# +....#.#.# +..##..#.. +.#####.#. +#.#.#...# +...###### +..#..###. +##...##.. +#.###.### +.##.###.# +###...##. +###...##. + +#.####### +#..###### +#..#....# +.#.##..## +..###..## +...#....# +##.#####. +####....# +####....# +##.#####. +...#....# +..###..## +.#.##..## +#..#....# +#..###### +#.####### +.#....... + +.###.##...####### +###..#.#####.#..# +.####.#.##.##.#.# +.##.....##.##.#.# +...######.##.#.## +...######.##.#.## +.##.....##.##.#.# +.####.#.##.##.#.# +###..#.#####.#..# +.###.##...##.#### +##.###...##..##.. +##.###...##..##.. +.###.##...##.#### +###..#.#####.#..# +.####.#.##.##.#.# + +..####..# +...#..### +#..####.. +#.#.#.##. +#####..## +..##.#.#. +..##.#.#. +#####..## +#.#.#.##. +#..####.. +...#..### +..####..# +####.#### +.###.#### +..####..# +...#..### +#..####.. + +.##..#. +#..#..# +....### +#..#.#. +#..#.#. +....### +#..#..# +.##..#. +#...#.. +####..# +.##..#. +.....#. +#..##.# + +#.##..##. +#...##... +...####.. +.######## +#..#..#.. +#..#..#.. +#...##... +.##.##.## +.###..### +#...##... +.###..### + +##.##........##.# +########..####### +...##.######.##.. +..#.#.##..##.#.#. +....###.##.###... +##.#..######..#.# +##...#.####.....# +..###........###. +#####...##...#### +..#####....#####. +....####..####... +..#..#.#..#.#..#. +#####...##...#### + +...#.######.#.. +..##........##. +##.##########.# +###.##.##.##.## +##.#..####..#.# +..#####..#####. +####.######.### +##.#..#..#..#.# +####..#..#..### +..##...###..##. +##...#.##.#...# + +..##....##. +##.##..##.# +..########. +..#.##.#.#. +..##....##. +..#.####.#. +##.######.# + +#..#..##....### +....#.#..##..#. +....##.#######. +....##.#######. +....#.#..##..#. +#..#..##....### +#..##...##.##.# +#####.#...#.... +.......#...#.## +.......######.. +.##.##.#.###... +.##.##.###.#.## +..#...###..#... + +...#..#.###.#.. +##.#####....### +.....##..##.##. +###.##..##..... +###.#.##..#.### +###..##.#..##.# +...#.##.##..##. +.....#...#.###. +..#...####.###. +..##.###...#### +..###...####### +###.#.##.#..#.. +........#..##.. +....#..#.##...# +....#....##...# + +#.##.#..#.# +#.##.#..#.# +###..####.. +.##.#..#.#. +...##.##.## +###.##..##. +#....####.. + +##.#.#.##.#.. +...##....#### +.##..##.##### +#.##.##...### +#....##..##.# +..##..#.##..# +..##..#.##..# +#....##..##.# +#.##.##...### +.##..##.##### +...##....#### +##.#...##.#.. +##.#...##.#.. + +........#..#... +#######.#.##### +.####.#.####... +.####.#...###.. +#.##.#....#..#. +.#..#......##.. +.......##..###. +##..##....##### +######.#..##### +######.#..##### +##..##...###### + +#..#....##... +..##.##.##.## +###..##.##.## +##...##.##.## +###.....##... +.....##.##.## +..###.#....#. +#......####.. +#.##......... +..######..### +##..####..### +..#.#........ +#.##...#..#.. + +##.#.#... +#.#...... +#....#### +#....###. +#.#...... +##.#.#... +..#.#.#.# +..#.#.#.# +##.#.#... +#.#...... +#....###. + +.##..##..###.## +.###.##..###.## +###.#....#..#.. +..#....#.##..#. +##...#..#....#. +..####.##.#.#.. +..####.##.#.#.. + +.##...### +#..#.#..# +...#.#..# +##.##.... +######..# +######..# +##.##.... + +########...####.. +...##....######## +...##....#......# +###...##.##....## +..####..#.#....#. +#.####.#.##....## +###..###.#.#..#.# +###..###.######## +.######..###..### + +###.#.. +.#...## +####... +##.#.## +####.## +####.## +..###.. +..#..## +###.### +..#.... +###.... +##.#.## +##..#.. +..##### +###..## + +#..#..##### +#..#..##### +#####.##.#. +###.....#.# +###.###...# +..#.#..##.# +..#.#..##.# +###.###...# +###....##.# + +#..#.#.#.#.## +####.#..##### +...#....#.#.# +#..##.###.... +.....###..##. +####..#....## +#..##..#.#..# +#..##..#.#..# +####..#....## + +.#.#...#.#..#.# +##.####...##... +#.###.#........ +.#.##...######. +.#.##...######. +#.##..#........ +##.####...##... +.#.#...#.#..#.# +.#..##..######. + +####..### +.###.#### +...###.## +.......## +..#.#.### +###.##.## +#..#.##.. +###..#### +###..#### +...#.##.. +###.##.## +..#.#.### +.......## + +####.##..#### +######.####.. +#####.###.### +#..#..#.#..#. +#..#..#.#..#. +#####.###.### +######.####.. +####.##..#### +....#......## +.##..#..#.#.. +.##.##..#.... +##.#..#.##... +#..##.##...#. +......#..###. +.....#..##.## + +#.##..###.... +....######### +##.###....... +...##..##.... +...#.#.##.... +.#.##..#..... +...#####.#### +######..##### +....#.####### +#.#######.... +.###...#.#..# \ No newline at end of file diff --git a/inputs/13a.txt b/inputs/13a.txt new file mode 100644 index 0000000..f226414 --- /dev/null +++ b/inputs/13a.txt @@ -0,0 +1,15 @@ +#.##..##. +..#.##.#. +##......# +##......# +..#.##.#. +..##..##. +#.#.##.#. + +#...##..# +#....#..# +..##..### +#####.##. +#####.##. +..##..### +#....#..# \ No newline at end of file diff --git a/src/13.cs b/src/13.cs new file mode 100644 index 0000000..db7df14 --- /dev/null +++ b/src/13.cs @@ -0,0 +1,134 @@ +using aoc2023.Util; + +namespace aoc2023; + +internal class Day13 : Day +{ + private int part1; + private int part2; + internal override void Parse() + { + var lines = Parsing.ReadAllLines($"{GetDay()}"); + + List grid = new(); + void ProcessGrid() + { + (int res1, int res2) = CheckGrid(grid); + part1 += res1; + part2 += res2; + } + + foreach (var line in lines) + { + if (line.Length == 0) + { + ProcessGrid(); + grid.Clear(); + } + else + { + grid.Add(line); + } + } + + ProcessGrid(); + } + + (int, int) CheckColumns(IList grid) + { + int part1Columns = 0; + int part2Columns = 0; + + for (int checkCol = 1; checkCol < grid[0].Length; checkCol++) + { + int columnSpread = System.Math.Min(checkCol, grid[0].Length - checkCol); + int leftCol = checkCol - 1; + int rightCol = checkCol; + + int matches = 0; + + for (int dx = 0; dx < columnSpread; dx++) + { + int leftMatch = leftCol - dx; + int rightMatch = rightCol + dx; + matches += grid.Count(l => l[leftMatch] == l[rightMatch]); + } + + int maxCount = columnSpread * grid.Count; + if (matches == maxCount) + { + part1Columns = checkCol; + } + else if (matches == maxCount - 1) + { + part2Columns = checkCol; + } + } + + return (part1Columns, part2Columns); + } + + (int, int) CheckRows(IList grid) + { + int part1Rows = 0; + int part2Rows = 0; + + for (int checkRow = 1; checkRow < grid.Count; checkRow++) + { + int rowSpread = System.Math.Min(checkRow, grid.Count - checkRow); + int upRow = checkRow - 1; + int downRow = checkRow; + + int matches = 0; + + for (int dy = 0; dy < rowSpread; dy++) + { + int upMatch = upRow - dy; + int downMatch = downRow + dy; + + string lineUp = grid[upMatch]; + string lineDown = grid[downMatch]; + + for (int i = 0; i < lineUp.Length; i++) + { + int c1 = lineUp[i]; + int c2 = lineDown[i]; + if (c1 == c2) + { + matches++; + } + } + } + + int maxCount = rowSpread * grid[0].Length; + if (matches == maxCount) + { + part1Rows = checkRow; + } + else if (matches == maxCount - 1) + { + part2Rows = checkRow; + } + } + + return (part1Rows, part2Rows); + } + + (int, int) CheckGrid(IList grid) + { + (int part1Lefts, int part2Lefts) = CheckColumns(grid); + (int part1Ups, int part2Ups) = CheckRows(grid); + + return (part1Lefts + part1Ups * 100, part2Lefts + part2Ups * 100); + } + + internal override string Part1() + { + return $"Columns and rows total: <+white>{part1}"; + } + + internal override string Part2() + { + return $"Smudged columns and rows total: <+white>{part2}"; + } +} \ No newline at end of file