diff --git a/resources/2023/13/example.1.txt b/resources/2023/13/example.1.txt index e69de29bb..3b6b5ccd5 100644 --- a/resources/2023/13/example.1.txt +++ b/resources/2023/13/example.1.txt @@ -0,0 +1,15 @@ +#.##..##. +..#.##.#. +##......# +##......# +..#.##.#. +..##..##. +#.#.##.#. + +#...##..# +#....#..# +..##..### +#####.##. +#####.##. +..##..### +#....#..# diff --git a/resources/2023/13/example.2.txt b/resources/2023/13/example.2.txt new file mode 100644 index 000000000..20dd0ca60 --- /dev/null +++ b/resources/2023/13/example.2.txt @@ -0,0 +1,17 @@ +.####..###... +..##.......## +##..##..#.#.. +........##### +#.##.####..## +#.##.###.#... +##..##.#..... +#.##.######.# +..##..##.#.## +#....##..#.## +##..##...#... +########.##.. +#....####.#.. +..##..#..#### +######.###.## +######.#.##.. +..##...#..### diff --git a/resources/2023/13/input.txt b/resources/2023/13/input.txt index e69de29bb..94583887d 100644 --- a/resources/2023/13/input.txt +++ b/resources/2023/13/input.txt @@ -0,0 +1,1419 @@ +#..###..##### +###..#....... +.##.#.#.###.. +#####....#### +#####....#### +.##.#.#.###.. +###..#....... +#..###..##### +#.##.##.....# +#########.### +#.##.#..#.### +#.##.#..#.### +#########.### +#.##.##.....# +#.####..##### +###..#....... +.##.#.#.###.. + +.....#########. +#.#..#...#..#.. +.####...#.#.#.. +#####...#.#.#.. +#.#..#...#..#.. +.....#########. +###..#....####. +.#...###..#...# +...#########.#. +##.##.##.#####. +##.##.##.#####. +...#########.#. +.#...###..#...# +###..#....####. +.....#########. +#.#..#...#..#.. +#####...#.#.#.. + +#.####..##### +.##..##...### +...##...##### +##..#.##..... +..##.#.#.#### +.##....###### +.#...###.#### +##.##..#.#### +#...##.#..... +...#.###.#..# +#.#...###.##. +....#..#..##. +##.......#..# +.#.##..#.#### +.#.##..#.#### +##.......#..# +....#..#..##. + +####.#. +##.#.## +#..#... +.#.#... +######. +...#.#. +...#.#. +######. +.#.#... +#.##... +##.#.## +####.#. +###..#. +##.###. +.....#. +.....#. +##.###. + +....##... +..##....# +...#.#.## +...#.#.## +..##....# +....##... +##...#..# +..#.#..#. +...###..# +##.####.# +..#...#.. +.#...###. +...#..#.. + +.#.######.#.... +##.#....#.##..# +#.##.##.##.#### +#.#...#..#.#### +############..# +...#.##.#...... +...#....#...... +###.#..#.###..# +..########..##. +.##########.... +.#.##..##.#.##. + +##..#.# +....##. +##...## +#...### +..#.### +.##..#. +...#.#. +...#.#. +.#...#. +.#...#. +...#.#. +...#.#. +.##..#. + +.####..###... +..##.......## +##..##..#.#.. +........##### +#.##.####..## +#.##.###.#... +##..##.#..... +#.##.######.# +..##..##.#.## +#....##..#.## +##..##...#... +########.##.. +#....####.#.. +..##..#..#### +######.###.## +######.#.##.. +..##...#..### + +...##.....#..## +..#..#.....#... +##.##.##.#..#.. +..#..#...##..## +..........##... +..#..#..##..#.. +#......###.#... +#..##..#..#.### +........#.#.... +##....##.#.##.. +##.##.###.#..## +##....###.##.## +#.####.#.#..#.. +.######...##... +...##..##..#.## +.##..##.#.###.. +.#....#.##.##.. + +.#.##..##.# +..##.##.##. +##..#..#..# +.#..####..# +#.......... +..##....##. +..##....##. +##..####..# +.########## +#....##.... +..##.##.##. +#.......... +#####..#### + +#....##.... +.#....#.#.. +..#...#.### +###...###.. +....#.#.### +#.#.##.#### +..#######.. +.##...#.#.. +.##...#.#.. +..#######.. +#.#.##.#### +....#.#.### +.##...###.. +..#...#.### +.#....#.#.. + +.#....##..# +#.#..###..# +#.##...#..# +#..#####..# +####.#.#..# +.#.###.#..# +####...#..# +.##.#.#.##. +#....#.#### +#.##...#..# +##..####..# +.###..##..# +.#.#..##..# +##..####..# +#.##...#..# + +#..##.#.#.#.. +#..##.#.#.##. +.##..#.....#. +.##..##...... +#####..###### +#.###.##...## +...##.#..##.. +#.##...#..#.# +...#..###..## +#.#.##..#.#.# +.....#..##### +#.#...#.#...# +#.#...#.#...# +.....#..##### +#.#.##..#.#.# +...#..###..## +#.##...#..#.# + +#..#.##..#### +####...#.#### +.##..#..##..# +.#..#.#.##..# +.###...#..... +#.#.###.##### +#.#.######### + +#.##.##.##.##..## +...#....#...#.... +.....##.....#.### +#...####...#.#... +..#.####.#..#.#.. +#....##....####.. +#...#..#...#.#### +.#.######.#..#.## +##.#.##.#.#####.. +.##......##.#.### +..###..###....### +............##... +###.####.###..### +#..##..##..#..... +.#..#.##..#...#.. + +.......#..##.## +..##...#.##.#.# +##..##.##.#..#. +##..######...#. +######..######. +..##..#.####..# +#.##.#.#.#..##. +######...##..## +##########...## +##..####.##.... +######...##.... +..##..####.##.# +..##..###.#.#.# + +#####.#.######. +#.##.#####.##.# +...#...#..##.## +.#......#..#.## +.#......#..#.## +...#...#..##.## +#.##.#####.##.# +#####.#.######. +....#.####.#### +...####..#.###. +...####.#.#.### +...####.#...### +...####..#.###. + +###..#### +....###.# +....###.# +#.#.##... +..#.....# +..#.....# +#.#.##... +....###.# +....###.# +###..##.# +....#.#.. +##....##. +.#.#..... +.#.#..... +##....##. + +....##. +.##.... +..##..# +#.##### +##.#### +###.... +##..... +##.#### +#.##### +..##..# +.##.... +....##. +.#..##. +#.#.... +.#..##. + +..#..#....##..# +..#..#......##. +##....##..#...# +.######.##..##. +##....###.##..# +.#.##.#...#.... +#.####.#.##.... + +.#.#...#.#.#..# +...###...##.##. +.##.....#...... +.##.....#...... +...###...##.##. +.#.#...#.#.#..# +#..##...###.#.. +..#.#.#.#..###. +..#.#.#.#..###. +#..##...###.#.. +.#.#...#.#.#..# +...###...##.##. +###.....#...... + +..#..#.#..# +..#..#.#..# +###..##...# +######.#.## +##....##### +..##.#.##.. +..##...###. +...#....### +..#.##..#.. +##.......## +##..##...#. +##..####.## +##..#.....# +.####..#..# +..##.....#. + +##..########... +#....###...#... +.......#.#...## +#....##..#.##.# +#######.#..#.## +..##...##....#. +#.##.#.#.###..# +#.##.##.#.##... +#.##.#.####...# +.#..#..#.#...## +.#..#..#.#...## +#.##.#.####...# +#.##.##.#.##..# + +##.##.###.....# +.....###.###.## +...#.#.##..##.. +..#.######..#.. +...#.#..#.##.## +..#..#.###..... +..##..#....##.. + +.#.###..##. +.#...#####. +#..##.###.# +..####.#... +#..#...#... +####.##..## +..###...... +..###...... +####.##..## +#..#...#... +..####.#... +#..##.#.#.# +.#...#####. +.#.###..##. +.#.###..##. + +##..##..#####.. +#.##.##..#...#. +#....#.##.#..## +##..######..### +..##...##..##.. +..##...##..##.. +##..######..### +#....#.##.#..## +#.##.##..#...#. +##..##..#####.. +....#.##..##.## +#.##.##.##..##. +.#..#.#..##.### + +.#..########..#.. +#...#......#...## +.#....####....#.. +######.##.####### +...##.#..#.##.... +#....######.#..## +###....##....#### +##.###.##.###.### +##.#..####..#.### +#..##......##..## +#.##...##...##.## +....########..... +.###.##..##.###.. +.##..##..##..##.. +##...#.##.#...### + +..#.##.#....# +##.#..#.####. +.########..## +#.#.##.#.##.# +..######....# +#..#..#..##.. +#.#.##.#.##.# +.#..##..#..#. +...#..#...... +#...##...##.. +#.##..##.##.# +#.######.##.# +##.#..#.###.. + +..#.#####.. +###..#.#.## +..##..##.#. +..##..####. +###..#.#.## +..#.#####.. +....##.#### +..##.#..... +..#.##.#### +#####...#.. +#####...... +###.#.#.#.. +..#...##### + +.##.#..#.#..##... +..#..##.......#.. +###..###.#..##.## +###.#.#####....## +....#.###.###.### +##.#.#...##.##... +###.#.####.#.#... +..#.#.###.##..### +##.#.#.....#..... +.....##.##..#.### +..#.#..######.### +..#..##.#####.### +##..##.##..###.## + +...#...## +.#....### +..#.#.#.. +.#.###.## +.##...... +#..#..#.. +#...##### +#.#.###.. +#.#.#.#.. +.##...### +.##...### +..#.#.#.. +#.#.###.. + +....####.##..## +#..###.#.#...## +#..###.#.#...## +....####.##..## +...##..##.#..#. +##.##.##....##. +#.#...##...#.## +..###.....#.#.. +#.##.#..###.#.. +...##.#....#..# +#...##.######.. +##.###...#....# +##.#.##...##..# +####........### +####........### +##.#.##...##..# +#..###...#....# + +..#......#..#.. +..#......#..#.. +##..####..##.## +.##########.#.. +.#.#....#.#.### +##.######.###.. +##.######.##... +..########.#.## +.#........#...# +....####......# +############... +####.##.####.## +.#.#....#.#.#.. + +##..###.#..## +#.##.#.###.#. +#.##.#.###.#. +##..###.#..## +.....#.#.##.. +........#.... +..##.....#..# +#.##.#.#..#.. +.####..#.###. +.####..#.#.## +.####.#....#. + +#..#..#.#.### +#...#.##.##.# +..##....#.... +####..###...# +####..###...# +..###...#.... +#...#.##.##.# +#..#..#.#.### +###.##...#... +.##..#.###.## +..##...##..## +..#.#..##...# +..#.#..##...# +..##...##..## +.##..#.###.## + +##.##.. +...#..# +...#..# +##.##.. +#.##### +##.#... +##.#.## +..#..## +####.## + +..#......#.#... +.##......##...# +##..####..####. +.....##.....### +##..#..#..##.#. +.#.##..##.#...# +#...#..#...#..# +#...#..#...#..# +.#.##..##.#...# +##..#..#..##.#. +.....##.....### +##..####..####. +.##......##...# + +#.#..#... +#.#..#... +...####.# +.##....## +###....## +...####.# +#.#..#... + +...#.#.##.#.#.. +.#..#......#..# +#.##.#.##.#.##. +#.##.#.##.#.##. +.#..#......#..# +...#.#.##.#.#.. +..#.#.#..#.#.#. +.#.#...##...#.# +.###.######.### +####.#....#.### +...#..####..#.. +..#...#..#...#. +#...#.####.#... +#..##########.. +#...##.##.##..# +#...#.#..#.#... +##.#.######.#.# + +####....### +###.####.## +....#..#... +....####... +..#......#. +##...##...# +..########. +..###..###. +..##.##.##. +####.##.### +##..####..# +###..##..## +..##....##. +####.##..## +##...##...# +####....### +##..#..#..# + +.##.###.### +.##.##..### +.##.##..### +.##.###.### +...#.#..#.# +..##...#... +##.#.#..#.# +#.##..#..#. +...###...#. +..#..##.... +..#.##.#### +......##... +##.#...#..# + +......#..#... +...#.###.#... +##.#...###.## +##.#...###.## +...#.###.#... +...#..#..#... +###.####.#..# +###.#.#..##.. +#######.#.### +##.##..#.###. +....##.#.##.# +###.###.#..#. +...#####...## + +#.##...#.#..### +##.#..#.#....#. +#..#..#.#....#. +#.##...#.#..### +##.###.##..#... +...#......#...# +.#.....#..#.##. +.###..#...#.### +.#...#####..##. +.#...#####..##. +.###..#...#.### +.#.....#..#.##. +...#......#...# + +...###..##..# +..###..###..# +..####.###..# +...###..##..# +..#...#.###.. +..#...###.#.. +..#..#.#..... +##..###.###.# +...##..#..#.# +...#..#..##.. +###.##...#.## +..##.#.#..#.. +..##.####.### + +##.##.##...##.. +#.#.#..###.##.# +#.#.#..###.##.# +##.##.##...##.. +#..###..#..##.. +##..##.###.##.# +.#..###...####. +.#.#####.#..#.# +#..#...##.#..#. + +######. +..#.... +##..#.# +.###.#. +#.##### +....#.# +....#.# +#.##### +.#.#.#. +##..#.# +..#.... +######. +######. + +##..#.#.... +##..#.#.... +..#.#.#.... +#######.##. +#.###...##. +###.##..##. +..#........ +.####.#.... +#.##...##.# +####...#### +..##.#..##. +..#.#...... +..##.#..... + +.##.##... +#...#.#.. +.##....#. +........# +#..##..#. +.##.#.#.# +....#..#. +####..##. +####..#.# +####..#.# +####..##. + +##..##.#..#.##. +####..#.##.#..# +..#.#...##...#. +.#..##.####.##. +#.##..##..##..# +.##.##.#..#.##. +.##....#..#.... +#..#####..##### +#.############# +.#..##.####.##. +.#..##.#..#.##. +#..#..#.##.#..# +.######.##.#### + +.#..#...#####.... +#.#.#.#.###...### +.#..##..#.#.#.#.# +.#######..#.#.### +...#.......###### +.##...##.#.##..## +.#.##...###.#.### +.#.##...###.#.### +.##...##.#.##..## + +###..####.# +###..####.. +#....##.#.. +#.....#.### +.#.##..###. +.#.##....#. +.##.##..#.# +.#..##.#... +...#.##.##. +...#.##.##. +.#..##.#... +.##.##..#.# +.#.##....#. +.#.##..###. +#.....#.### + +.#.##.# +#...... +.##..## +...##.. +...##.. +.##..## +#...... +.###### +.#....# +#.#..#. +###..## +..#..#. +#...... +##....# +.###### +##....# +.#....# + +.#..#.#.##....# +.....#.##...#.# +.....#.##...#.# +.#..#.#.##....# +.####..#..##..# +...###...##.##. +..##.#..##..#.. +##..#.#####...# +#.###.#.....#.# +#.#.##.##..##.# +#.#.##.##..##.# +#.###.#.....#.# +##..#.#####...# +..##.#..##..#.. +...###...##..#. + +..#.##.###.#. +#..##...#.#.. +#.##...#..##. +#.###.##.#... +.#.##....#... +#.##.###..#.. +......#.#.#.# +......#.#.#.# +#.##.###..#.. +.#.##....#... +#.###.##.#... +#.##...#..##. +#..##...#.#.# +..#.##.###.#. +..#.##.###.#. + +.##.#.#.##. +.##.##....# +.##.##....# +.##.#.#.##. +.##.##.#.## +#..#..#.#.. +.....##.##. +.##.##..... +....###...# +.#####....# +#####.#...# +#####...#.. +#..#.#.#### +.##.#####.# +.##..##..## + +...##.#..#. +.#.##.####. +.#...#.##.# +#.######### +..######### +##...#....# +##...#.##.# +..######### +#.######### + +###..##..######## +....#..#.#..####. +#.#..##..#.#....# +..#..##..#..#..#. +##.#....#.####### +###......###....# +.#.##..##.#.####. +#...####...###### +.#.#.##.#.#...... +###.####.###....# +#..........#....# +..#.####.#..#..#. +...##..##....##.. +.#.##..##.#..##.. +...##..##........ +.#.#....#.#...... +..##.##.##...##.. + +..#.#....## +......#.... +...#...#.#. +.###..#.#.. +.#.#.##..## +#..####..## +#..####..## + +....#...# +###.#...# +#####..## +#######.. +..#.##.#. +##..#.... +###..##.# +###..##.# +##.##.... + +..##.#...#..# +..#..###..### +###.....#.#.. +..##..#...#.# +##....#..##.. +##....#..##.. +..##..#...#.# +###.....###.. +..#..###..### +..##.#...#..# +####...#..### +..#.##..#..## +..#...##.#... + +..#..##.##..#.# +#####....#.##.. +.#..##..######. +#####...##.#### +..##.#.##....## +...#####.#.#### +..##..#...#.### +.###..#...#.### +...#####.#.#### +..##.#.##....## +#####...##.#### +.#..##..######. +#####....#.##.. +..#..##.##..#.# +.###..###.#.#.# +.###..###.#.#.# +..#..##.##..#.# + +#...#.#.. +#...#.#.. +..##.#... +##..##... +.#...##.. +#..###.## +#.#####.. +.#....##. +.#..###.. + +#..##..#.#...##.# +......#....####.# +.##.####.######.# +........####.#..# +#####.#..##.#.... +#..##..#.###..#.# +#..####.########. +#..####..#######. +#..##..#.###..#.# +#####.#..##.#.... +........####.#..# + +#...##.##.#.. +##.##..###.## +#.######...## +##.#.######## +.#....#...... +#.#..##.##... +.##.#.##...## +##..###.#.... +..####...#.## +.##.####..### +#...##.#.##.. +#...##.#.##.. +..#.####..### + +#....#. +#.###.. +#.###.. +#....#. +..###.. +.####.. +.....#. +...#.#. +####..# +..###.. +#...#.. +......# +##...#. +##...#. +......# +#...#.. +...##.. + +#..#..#.####.#. +..#.###.#####.. +.....#.###...#. +..#....#.#.##.# +..##..##.#.#### +..#####.....#.. +..#####.....#.. +.###..##.#.#### +..#....#.#.##.# +.....#.###...#. +..#.###.#####.. +#..#..#.####.#. +.#####.##.#..## +.#####.##.#..## +#..#..#.####.#. + +......# +..##... +......# +.#..#.# +##..### +#....## +##..##. +##..### +##..### +##..##. +#....## +##..##. +.#..#.# +......# +..##... + +#....##.# +.######.# +#.#..##.# +.#.###.## +.#.###.## +#.#..##.# +.######.# +#....##.# +#..###... +..#.#..#. +#.###.##. +###.##### +.###..##. +#.###.##. +#.###.##. +.####.##. +###.##### + +.#.##.#.#..#. +.#.##.#.#.... +##.##.##....# +..###...##..# +...##....#.## +.....##.##.## +###.....#.### +.##.###.#..#. +.##.###.#..#. +###.....#.### +.....##.##.## + +######.###### +.##....#...## +#####.#.##... +.##.#.###..## +.....#...#... +#..#####.#.## +#######.#.... +.##...#..#.## +....##..###.. +##.###...#... +.##.##....... +.....#.###... +#####.##...## +.##.......### +.##..##..##.. + +#......#..#....## +#..##..##....#### +#.####.##..#.##.# +..#..#..#..#..#.# +.#....#..#.##..#. +##.##.###.##.#### +........#.#...#.. +.#....#.##.....#. +...........##..## +##.##.#####...... +##..#.##.#..#.##. +#..##..#.#.####.# +#..##..#.#.####.# + +.#..#..#..# +.###....### +#..#.##.#.. +####....### +####....### +#..#.##.#.. +.###.##.### + +....#..##..#..... +.##.#......#.##.. +.######..###.##.. +.......##........ +##.#........#.### +#..#..####..#..## +.##...####...##.. +####........##### +..###.#..#.###... +.####.####.####.. +.#..###..###..#.. +.###..####..###.. +..#.#.####.#.#... +..#.##.##.##.#... +##....####....### +#.##..####..##.## +###..#.##.#..#### + +.##.##.....## +#.#..#...#.#. +..##...##.### +..##...##.### +#.#..#...#.#. +.##.##....### +##..#.....#.# +.#..#..#.#### +....#####.##. +....#####.##. +.#..#..#.#### + +#..#..######..#.. +.##.#.#....#.#.#. +#.#.#...##...#.#. +.....##....##.... +.#.#..#....#..#.# +#.....##..##..... +#.....##..##..... + +.####.##.##.##. +..##...#....#.. +.####.#.####.#. +.......######.. +..##........... +#....#...##...# +.####...####... +.......#....#.. +......#.####.#. +##..########### +######.##..##.# +.####.#.#..#.#. +......##....##. +#.##.########## +.......#.####.. + +#.#....#.#..# +.###..###.#.. +.##....##...# +...#..#....## +#........#.#. +####..####... +....##....##. +....##....##. +####..####.#. + +.###.#.###..# +.....#####.## +.#.##.##..##. +...##..#.##.. +######...#... +######...#... +...##..#.##.. +.#.##.##..##. +.....#####.## +.###.#.###..# +###...##.#.#. +..#..##.#.#.# +###.#..#...#. +#.##.##.#..## +#.##.##.#..## +###.#..#...#. +.....##.#.#.# + +...#..#.#.# +#...#.#..## +...#.#.#.#. +#.###...#.. +....#...##. +....#...##. +#.###...#.. +...###.#.#. +#...#.#..## +...#..#.#.# +.#...###... +####....#.. +####....#.. +.#...###... +...#..#.#.# +#...#.#..## +...###.#.#. + +.#...#. +.#...#. +#...#.. +##.#..# +#####.# +..#.... +##...## +##...## +#.#.... +#####.# +##.#..# +#...#.. +.#...#. + +.....###......# +.##...#...#.... +#..##..##.###.. +....##.#....#.# +#####...###.... +.##..##....#.#. +#..#..#..#...## +####.#.#####.#. +.##...##....#.. +....#.##.#####. +....#.##.#####. +.##...##...##.. +####.#.#####.#. +#..#..#..#...## +.##..##....#.#. +#####...###.... +....##.#....#.# + +.##..##..#. +.######..#. +#.####.##.. +#.#....#.#. +.######.##. +#..##..#..# +###..###.## +#..##..#... +.#.##.#..#. +#.####.#... +.######..#. +#########.# +#.####.#... +.#.##.#..## +.######.##. +.######.##. +.#.##.#..## + +#.#....###....# +#.#.####.###### +.####.#...#..#. +#....#..####### +##.#.#....####. +#####..#.###### +#####..#.###### +##.#.#....####. +#.......####### + +.#..##.## +#.....### +.##.#.### +#..#.#... +#..##..## +...##.... +#...#..## +.####.#.. +##..##### +.#....#.. +.#..#.... +......#.. +......#.. +.#..#.... +.#...##.. +##..##### +.####.#.. + +...############## +..##.....##...... +#.....###.##.##.# +#.#.##.#####....# +##.#....#.....#.. +#...#..##.#.####. +.##.#..#.##.#..#. +#...##..#..#....# +#...##..#..#....# + +.##.##### +#...#..#. +#.#..##.# +##....#.. +.#..##.#. +.#..##.#. +##....#.. +#.#..##.# +#...#..#. +..#.##### +.##.#.##. +..#..#.## +#####..#. +#####..#. +..#..#.## + +.#.#......#.#.. +#..########..## +.####....####.. +#..###..###..## +#.##..##..##.## +..#........#... +.############.. +#..#.#..#.#..## +##.########.### +.##.###.##.##.. +.#....##....#.. +###...##...#### +##..##..##..### + +.##.#..#..#.. +.......#..#.. +.###.#.####.# +..####.#..#.# +......######. +.#####.#..#.# +.##..######## +..##.#.#..#.# +....###....#. +#...#..#..#.. +#...#..#..#.. + +##..#..#. +##..#..#. +#.###.##. +#..#...## +.#.#...## +.##....## +....##..# +....##..# +.##....## +.#.#...## +#..#...#. + +##.##.#.. +..#....#. +######.## +..####.#. +....#.##. +###.###.. +..###.#.# +##...#.## +..##.#.## +##..#..#. +..#.###.# +....#..## +..#...##. +..###.##. +..#.##... +###.#.### +###.##### + +##..##..# +.##.#.#.# +...#.##.. +#..#.##.. +.#####... +..##.#### +..#..#### +..#..#### +..##.#### + +...####.... +##......### +#.#....#.## +#.######.## +#..#..#..## +#.##..##.## +##..##..#.. + +.....##.###..###. +#....##.###..###. +.##....##.####.## +.#.##.#####..#### +#.....#.###..###. +##..#.#..#.##.#.. +##.#.....#....#.. +#.#.#.##..####..# +####..###.#..#.## + +.#..##.#.#####. +.#..##.#.#####. +#..#.#.###.#... +.#.#.#.##..#... +..#...#.#...##. +......#.####.## +###...##.#..### +##....##.#..### +......#.####.## + +#.###.# +####... +.#....# +.#....# +####... +#.###.# +#.###.. +###.### +.....## +.##..## +###...# +##....# +.##..## +.....## +###.### + +#.##.##.##.#..# +..##....##..### +.####..####...# +.####..####..## +#.##.##.##.#..# +############.#. +############... +#.##.##.##.#... +############... +#.##.##.##.#.## +.####..####.##. +##..####..##... +#.##.##.##.#### +#....##....###. +############.#. +............### +..###..###..##. + +.#..#.#.#.#.#.... +#########.##.#### +#########.##.#### +.#..#.#.#.#.##... +#.##.#.#..#.#.... +..#####.#.#..#... +.##.#.#...##.#... +...###.#.##..#... +#.....###....#.#. +..#..####.##..##. +#.#..#...####.... +#.#..#...####.... +..#..####.##..##. +#.....###....#.#. +...###.#.##..#... +.##.#.#...##.#... +..#####.#.#..#... + +.##.##.##..## +...####..##.. +#..#.....##.. +.##.##.#.##.# +####.#...##.. +#..#####.##.# +.##.#.#.#..#. +######.###### +....#.##.##.# + +.#######..#.. +...#.#.#...## +...#.#.#....# +.#######..#.. +.#######..#.. +...#.#.#....# +...#.#.#...## +.#######..#.. +.#..#.#.##.#. +....####..... +#..##.#.##### +##...######## +.##.#...#..#. + +..#..##..## +..#..##..## +##...#.#.#. +#.#.#.#.... +.###..####. +##.#.....## +..#.#.##..# +...#...##.. +#########.# +#####.###.# +...#...##.. +..#.#.##..# +##.#.....## +.###..####. +#.#.#.#.... diff --git a/solutions/typescript/2023/13/src/p1.spec.ts b/solutions/typescript/2023/13/src/p1.spec.ts index fc914d7d9..b22b8c446 100644 --- a/solutions/typescript/2023/13/src/p1.spec.ts +++ b/solutions/typescript/2023/13/src/p1.spec.ts @@ -1,20 +1,39 @@ import { loadTaskResources } from '@alexaegis/advent-of-code-lib'; import { describe, expect, it } from 'vitest'; import packageJson from '../package.json'; -import { p1 } from './p1.js'; +import { findReflectivePairings, p1 } from './p1.js'; describe('2023 13 p1', () => { describe('the input', () => { it('should solve the input', async () => { const resources = await loadTaskResources(packageJson.aoc); - expect(p1(resources.input)).toEqual(0); + expect(p1(resources.input)).toEqual(37_718); }); }); describe('example 1', () => { it('should be solved', async () => { const resources = await loadTaskResources(packageJson.aoc, 'example.1.txt'); - expect(p1(resources.input)).toEqual(0); + expect(p1(resources.input)).toEqual(405); + }); + }); + + describe('findReflectivePairings', () => { + it('should be able to collect reflective pairs from the middle', () => { + const result = findReflectivePairings(0, 8, 4); + console.log(result); + expect(result.length).toEqual(4); + expect(result[0]).toEqual([4, 5]); + expect(result[1]).toEqual([3, 6]); + expect(result[2]).toEqual([2, 7]); + expect(result[3]).toEqual([1, 8]); + }); + + it('should be able to collect reflective pairs from the start', () => { + const result = findReflectivePairings(0, 8, 0); + console.log(result); + expect(result.length).toEqual(1); + expect(result[0]).toEqual([0, 1]); }); }); }); diff --git a/solutions/typescript/2023/13/src/p1.ts b/solutions/typescript/2023/13/src/p1.ts index fd0570f56..cbe680667 100644 --- a/solutions/typescript/2023/13/src/p1.ts +++ b/solutions/typescript/2023/13/src/p1.ts @@ -1,8 +1,124 @@ -import { task } from '@alexaegis/advent-of-code-lib'; +import { + DOUBLE_NEWLINE, + GridGraph, + GridGraphNode, + task, + type ToString, +} from '@alexaegis/advent-of-code-lib'; import packageJson from '../package.json'; -export const p1 = (_input: string): number => { - return 0; +const getColumn = = GridGraphNode>( + gg: GridGraph, + column: number, +): N[] | undefined => { + const aabb = gg.boundingBox(); + return aabb.horizontal.contains(column) + ? aabb.vertical.map((row) => { + const node = gg.getNode({ x: column, y: row }); + if (!node) { + throw new Error(`problem while fetching row: ${row} column: ${column}`); + } + return node; + }) + : undefined; }; -await task(p1, packageJson.aoc); // 7118 ~30.83ms +const getRow = = GridGraphNode>( + gg: GridGraph, + row: number, +): N[] | undefined => { + const aabb = gg.boundingBox(); + return aabb.vertical.contains(row) + ? aabb.horizontal.map((column) => { + const node = gg.getNode({ x: column, y: row }); + if (!node) { + throw new Error(`problem while fetching row: ${row} column: ${column}`); + } + return node; + }) + : undefined; +}; + +const matchingNodes = = GridGraphNode>( + a: N[], + b: N[], +): boolean => { + return a.zip(b).every(([an, bn]) => an.value === bn.value); +}; + +export const findReflectivePairings = ( + low: number, + high: number, + reflectionOrigin: number, +): [number, number][] => { + return reflectionOrigin + .interval(high) + .collectValues() + .filterMap((right) => { + const left = reflectionOrigin - (right - reflectionOrigin); + return left >= low ? [left, right + 1] : undefined; + }); +}; + +const findColumnReflection = < + T extends ToString = string, + N extends GridGraphNode = GridGraphNode, +>( + gg: GridGraph, +): number | undefined => { + const aabb = gg.boundingBox(); + return aabb.horizontal.collectValues().find((column) => { + const pairs = findReflectivePairings(aabb.horizontal.low, aabb.horizontal.high, column); + return ( + pairs.length > 0 && + pairs.every(([left, right]) => { + const leftColumn = getColumn(gg, left); + const rightColumn = getColumn(gg, right); + return !leftColumn || !rightColumn || matchingNodes(leftColumn, rightColumn); + }) + ); + }); +}; + +const findRowReflection = < + T extends ToString = string, + N extends GridGraphNode = GridGraphNode, +>( + gg: GridGraph, +): number | undefined => { + const aabb = gg.boundingBox(); + return aabb.vertical.collectValues().find((row) => { + const pairs = findReflectivePairings(aabb.vertical.low, aabb.vertical.high, row); + return ( + pairs.length > 0 && + pairs.every(([top, bottom]) => { + const topRow = getRow(gg, top); + const bottomRow = getRow(gg, bottom); + return !topRow || !bottomRow || matchingNodes(topRow, bottomRow); + }) + ); + }); +}; + +export const p1 = (input: string): number => { + return input + .split(DOUBLE_NEWLINE) + .map((m) => m.toGridGraph()) + .map((gg) => { + const columnReflectionIndex = findColumnReflection(gg); + const rowReflectionIndex = findRowReflection(gg); + console.log('verticalReflectionIndex', columnReflectionIndex); + console.log('rowReflectionIndex', rowReflectionIndex); + let value = 0; + if (columnReflectionIndex !== undefined) { + value = columnReflectionIndex + 1; + } + if (rowReflectionIndex !== undefined) { + value = (rowReflectionIndex + 1) * 100; + } + return value; + }) + .sum(); +}; + +await task(p1, packageJson.aoc); // 37718 ~0ms diff --git a/solutions/typescript/2023/13/src/p2.ts b/solutions/typescript/2023/13/src/p2.ts index 49109df1b..e3bc905e7 100644 --- a/solutions/typescript/2023/13/src/p2.ts +++ b/solutions/typescript/2023/13/src/p2.ts @@ -1,8 +1,189 @@ -import { task } from '@alexaegis/advent-of-code-lib'; +import { + DOUBLE_NEWLINE, + GridGraph, + GridGraphNode, + Vec2, + task, + type ToString, +} from '@alexaegis/advent-of-code-lib'; import packageJson from '../package.json'; -export const p2 = (_input: string): number => { - return 0; +const getColumn = = GridGraphNode>( + gg: GridGraph, + column: number, +): string[] | undefined => { + const aabb = gg.boundingBox(); + return aabb.horizontal.contains(column) + ? aabb.vertical.map((row) => { + const node = gg.getNode({ x: column, y: row }); + if (!node) { + throw new Error(`problem while fetching row: ${row} column: ${column}`); + } + return node.value.toString(); + }) + : undefined; }; -await task(p2, packageJson.aoc); // 7118 ~30.83ms +const getRow = = GridGraphNode>( + gg: GridGraph, + row: number, +): string[] | undefined => { + const aabb = gg.boundingBox(); + return aabb.vertical.contains(row) + ? aabb.horizontal.map((column) => { + const node = gg.getNode({ x: column, y: row }); + if (!node) { + throw new Error(`problem while fetching row: ${row} column: ${column}`); + } + return node.value.toString(); + }) + : undefined; +}; + +const matchingNodes = (a: string[], b: string[]): boolean => { + return a.zip(b).every(([an, bn]) => an === bn); +}; + +export const findReflectivePairings = ( + low: number, + high: number, + reflectionOrigin: number, +): [number, number][] => { + return reflectionOrigin + .interval(high) + .collectValues() + .filterMap((right) => { + const left = reflectionOrigin - (right - reflectionOrigin); + return left >= low ? [left, right + 1] : undefined; + }); +}; + +const findColumnReflection = < + T extends ToString = string, + N extends GridGraphNode = GridGraphNode, +>( + gg: GridGraph, +): number | undefined => { + const aabb = gg.boundingBox(); + return aabb.horizontal.collectValues().find((column) => { + const pairs = findReflectivePairings(aabb.horizontal.low, aabb.horizontal.high, column); + return ( + pairs.length > 0 && + pairs.every(([left, right]) => { + const leftColumn = getColumn(gg, left); + const rightColumn = getColumn(gg, right); + return !leftColumn || !rightColumn || matchingNodes(leftColumn, rightColumn); + }) + ); + }); +}; + +const findRowReflection = < + T extends ToString = string, + N extends GridGraphNode = GridGraphNode, +>( + gg: GridGraph, +): number | undefined => { + const aabb = gg.boundingBox(); + return aabb.vertical.collectValues().find((row) => { + const pairs = findReflectivePairings(aabb.vertical.low, aabb.vertical.high, row); + return ( + pairs.length > 0 && + pairs.every(([top, bottom]) => { + const topRow = getRow(gg, top); + const bottomRow = getRow(gg, bottom); + return !topRow || !bottomRow || matchingNodes(topRow, bottomRow); + }) + ); + }); +}; + +export const p2 = (input: string): number => { + return input + .split(DOUBLE_NEWLINE) + .map((m) => m.toGridGraph()) + .map((gg) => { + gg.print(); + console.log('----'); + let columnReflectionIndex: number | undefined = undefined; + let rowReflectionIndex: number | undefined = undefined; + + const unsmudgedRowIndex = findRowReflection(gg); + const unsmudgedColumnIndex = findColumnReflection(gg); + console.log( + 'unsmudgedRowIndex', + unsmudgedRowIndex, + 'unsmudgedColumnIndex', + unsmudgedColumnIndex, + ); + + const possibleSmudges = gg.boundingBox().renderIntoVectors(); + possibleSmudges.sort((b, a) => + a.manhattan({ x: unsmudgedColumnIndex ?? b.x, y: unsmudgedRowIndex ?? b.y }), + ); + + let smudge: Vec2 | undefined = undefined; + for (const possibleSmudge of possibleSmudges) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const smudgyNode = gg.getNode(possibleSmudge)!; + const originalNodeValue = smudgyNode.value.toString(); + smudgyNode.setValue(originalNodeValue.toString() === '.' ? '#' : '.'); + + const nextRowReflectionIndex = findRowReflection(gg); + const nextColumnReflectionIndex = findColumnReflection(gg); + + if ( + nextRowReflectionIndex === unsmudgedRowIndex && + nextColumnReflectionIndex === unsmudgedColumnIndex + ) { + smudgyNode.setValue(originalNodeValue); + + continue; + } + console.log( + 'smudge at', + possibleSmudge.toString(), + 'nextRowReflectionIndex', + nextRowReflectionIndex, + 'nextColumnReflectionIndex', + nextColumnReflectionIndex, + ); + + if ( + nextRowReflectionIndex !== undefined || + nextColumnReflectionIndex !== undefined + ) { + gg.print(); + smudge = possibleSmudge; + rowReflectionIndex = nextRowReflectionIndex; + columnReflectionIndex = nextColumnReflectionIndex; + smudgyNode.setValue(originalNodeValue); + break; + } + smudgyNode.setValue(originalNodeValue); + } + + if (!smudge) { + columnReflectionIndex = unsmudgedColumnIndex; + rowReflectionIndex = unsmudgedRowIndex; + + // throw new Error('Should be exactly 1 smudge'); + } + console.log('!!!!!!!!! Smudge found! (examp1, 0,0 and 1,4)', smudge?.toString()); + + console.log('verticalReflectionIndex', columnReflectionIndex); + console.log('rowReflectionIndex', rowReflectionIndex); + let value = 0; + if (columnReflectionIndex !== undefined) { + value = columnReflectionIndex + 1; + } + if (rowReflectionIndex !== undefined) { + value = (rowReflectionIndex + 1) * 100; + } + return value; + }) + .sum(); +}; + +await task(p2, packageJson.aoc); // 0 ~0ms +// too high 43113