From bd396f32d75bbba7f90e93496428f6874b03c9c8 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 13 Dec 2023 10:08:30 +0000 Subject: [PATCH 1/4] 2023: d13: ex1: add input --- 2023/d13/ex1/input | 1349 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1349 insertions(+) create mode 100644 2023/d13/ex1/input diff --git a/2023/d13/ex1/input b/2023/d13/ex1/input new file mode 100644 index 0000000..6d7d1e2 --- /dev/null +++ b/2023/d13/ex1/input @@ -0,0 +1,1349 @@ +######..# +.##....#. +.....##.# +.....##.# +.##..#.#. +######..# +#..#..### +.##..#.## +#####.#.# +#..#.##.. +.....###. +#####.... +....##.#. + +##..###.###.. +##.#.#..##..# +..#.#...#.#.# +######.#.#### +##..#.##....# +##.##.#..#.#. +#####....#.#. +###.########. +#######..#.## +..####..##..# +......#.###.. +......#.###.. +..####..#...# + +....#....##..##.. +##.#.....#....#.. +....##...#.##.#.. +..##..#####..#### +###..##..######.. +.....##.#.#..#.#. +.#.#####.##..##.# +###.###...####... +....####.#....#.# + +#.##.#.####.# +.#..#..#..#.. +.####.#....#. +#....#......# +.#..#.#....#. +.##.#.######. +#....######## +#....##....## +########..### +.#..#..####.. +.#..#..####.. +..##....##... +.####...##... +.#..#.##..##. +##..######### + +#.##.#.## +#....##.. +.......## +#....##.. +#....#### +#.####.## +.####.### + +.###.#### +.##.##..# +.###.#### +#....#..# +....#.... +##.##.... +##.###..# +#..#..##. +.#...#..# +....#.... +##.###### +...###.## +#.###.... +##.#.#### +##.#.#### + +......##.## +####..###.. +.##....#.#. +######.#### +######.#### +.##....#.#. +####..###.. +......##.## +.##.##.##.# +...##..###. +....###.##. +#..#......# +....##..... +#####.#.#.. +.....#..##. + +###.....###..## +#.#..#..##...## +..##.#...###.## +..##.#...##..## +#.#..#..##...## +###.....###..## +.##.#...#.#...# +##...#####.###. +##.#...###....# +#.####..#.#.#.. +#.##..###.###.. +#.##..###.###.. +#.####..#.#.#.. +##.#...###....# +##...#####.###. + +..###..#....#.. +##.....#.##.#.. +###....#.##.#.. +###.#..#....#.. +..##.#........# +####........... +..##...##..##.. +##...#.######.# +..#.#.########. +##....#.####.#. +##.#.####...### +##...#.#....#.# +##...##.#..#.## + +##..#..#..##..# +.###....###.#.. +.#...##...#..#. +..##.##.##..... +.#.#.##.#.#.#.# +.....#........# +.#..####..#.##. +####.##.####.## +####.##.####.## + +.#.#..####. +#.####.##.# +..#..###### +..#...####. +..#...####. +..#..###### +#.####.##.# +.#.#..####. +#..#.##..## +#.#.####### +###........ +....##....# +..#.###..## +...#..#.##. +.#.#.##..## + +##...#...##.#.#.# +##.#.......#.#.## +##.#.......#.#.## +##.......##.#.#.# +###....#.##.#...# +.#.#.#..#.###.##. +.#...#..##....... +#..#.#....#.##.## +.#.##...###.#..## +.##.#.#.#.#...### +#...##..#...#.##. +.#.####...#..#.## +.#.####...#..#.## +#...##..#...#.##. +.##.#.#.#.#...### + +.....#.##..##.# +.....#.##..##.# +.##.##.##..##.. +....#..#....#.. +#..#.###....### +##..#.##.##.##. +#...##........# +.#..#.###..###. +..##...#....#.. +#....#.##..##.# +#.##..###..###. + +.##.....#..#. +.##..#.###### +#.#...#...... +.###..#...... +..#..#..#..#. +..#..#..#..#. +.###.##...... +#.#...#...... +.##..#.###### +.##.....#..#. +........####. +.####.##....# +.#.##.#...... +######..####. +.#.##..##..## +....##.#....# +.###.#.###### + +###.#.####.#. +###.#.####.#. +...#.#.##.#.# +###...#..#... +.#.#.#....#.# +##..#..#...#. +..###..##..## +####..#..#..# +#...#......#. +..##..####..# +.#..########. +.#.#.#....#.# +#..####..#### +.#........... +#.#.#.#..#.#. + +#.#.... +#.#.... +#..#..# +..##..# +#...... +#...... +..#.##. +#.#.##. +#.##... +..#.##. +#.#.##. +#.##### +#.##### +.#.#### +##..##. + +.##.....### +#..###.##.# +.##..#.##.. +.....#.#.#. +#..##.#..## +#..##.#..## +.....#.#.#. +.##..#.##.. +#..###.##.# +.##..#..### +#..##..##.# +####...##.# +#..#.#.#.#. +........#.# +....####... +....#.###.# +.##.#.#..#. + +###.######. +...##.##.## +.###.#..#.# +....######. +.#.######## +#####....## +..##..##..# +#.##..##..# +##....##... +.#..#...... +#####....## +##....##... +.##.######. +###..####.. +....#.##.#. +....#.##.#. +###..####.. + +#.####..####.##.. +##..##..##..##.## +.#....##....###.. +###...##...###.## +#.#........#.#.## +.#.##....##.#.### +.#..........#.... +.#..........#.### +##.##.##.##.##### +##..........##### +.#..........#.### +.#####..#####.... +#..##....##..##.. + +#.##.#.#### +.###.###### +#..#....##. +#...####### +##.##..#..# +...#.###### +#.##....... +.#......... +##.####.##. +#..####.##. +.#......... +#.##....... +...#.###### +##.##..#..# +#...####### +#..#....##. +.###.###### + +.#...###... +.....##.### +..#..##.#.. +####....... +..##..#.##. +######.###. +########..# +########..# +######.###. +..##..#.##. +####....... + +##....###.. +###..####.. +..#..#..##. +...##...#.# +.#.##.#.##. +##.##.####. +########.## +..#..#..##. +########.#. +##.##.##... +...##...### +#########.. +...##....## + +#.....###.... +#.##.####.##. +#..#..##..#.. +##...#..#...# +.....#..#.... +####..##..### +..##......##. +##..######..# +##.##....##.# +##.##....##.# +##..######..# + +.####.##.#.#..##. +.....######..#..# +..#..######..#..# +.####.##.#.#..##. +######..##...#### +#..##.#..#.###### +..#....#.##...... +.##.#..###...#### +.....#..#..##.... +##.#..##.###..##. +#..##.#.##.#.#..# +..##.#.##...##..# +####.......#..... +.###.####...##..# +#..#..#.#####.... +###.#.#..###..... +####...######.... + +#####.###...# +##..#.#.###.. +#..#..##..#.# +##...##.#..#. +#####....##.# +.....##...### +#####.#.#.### +#####.#.#.### +.....##...### + +..##### +.#..... +.###### +#..#### +.###### +..#.... +###.... +###.... +##.#### +..#.##. +.#.#### +.###### +.#.#### +#.##### +##..... + +####....#...#.### +.#..#..####.##..# +.##.##.##..#####. +......##.##.##### +###.#.##.#####.## +.####....#...#### +.##.#....#...#### +###.#.##.#####.## +......##.##.##### +.##.##.##..#####. +.#..#..####.##..# +####....#...#.### +####....#...#.### + +###...#..#...## +...#......#.#.. +....#......#... +##..#.####.#..# +##..#.#..#.#..# +##.#.######.#.# +....#.####.#... +..##.#.##.#.##. +##...######...# +###.#..##..#.## +..#..######..#. + +.##..##..##..#### +####.##.####..... +.###.##.###..#### +..#.#..#.#...#### +.............#..# +...######...#.##. +..#.#..#.#..####. + +##.##.#.# +###.#.#.# +###.#.#.# +##.####.# +...#####. +...###### +...#..### +..######. +##...##.# +##...#..# +#####.#.. + +#.###.. +####.## +.#.##.. +....### +.##.... +.##.... +.#..### + +......#....#..... +#..#.########.#.. +.##.##......##.## +....#.######.#.#. +.#..##########..# +#.#..###..###..#. +####..######..### +#.##..#.##.#..##. +#..#..######..#.. +.#.#..##..##..#.# +#.#...#.##.#...#. +.#.##.#.##.#.##.# +.#.##.#.##.#.##.# + +###..## +#....## +###..#. +##..... +..#..## +#....## +#...### +###.### +..##.## +...##.. +...##.. +..##... +##.#... +..#.... +.##.### +###.... +###.... + +####.###..# +.......###. +......####. +####.###..# +###..#.#### +###.#....## +..#.#.....# +###.##.#.## +##.###.###. +####.##.#.. +##..#.#.#.. + +#..##.....##. +.......#..#.# +.##..#...#.## +.##..#...#.## +.......#..#.# +#..##.....##. +.##..#.###### +######.##.... +####...##.... +....#.##.#.## +#.....####... +.##..###..... +#####..#....# + +#..####..#... +####..#####.. +###....###.#. +..#....#..#.. +.#.#..#.#.### +.###..###.... +###########.. +#...##...#.## +...........## +..#....#...## +#.#....#.#### + +.##...#.# +.##..#... +.##.###.. +.##..#.#. +.##....## +#####.##. +.##...### +#..#..#.# +#..#..#.# +.##...### +########. +.##....## +.##..#.#. +.##.###.. +.##..#... + +.##.#....###..# +.##.#....###..# +..#######...... +.######.#.##.## +..#.#..#...###. +##....#.#.###.. +##....#.#.###.. +..#.#..#...###. +.######.#.##.#. +..#######...... +.##.#....###..# + +.##..####.. +.##..####.. +###...##... +...###..### +..#.#.##.#. +...######.# +...#..##..# +...#.#..#.# +#.#.##..##. + +##.#......... +#.####..##..# +##.#.######## +##.##........ +##.########## +#.#.......... +.#.#......... +#.########### +.###.#......# +###.......... +#.#.#.##..##. +.#....##..##. +#.#...##..##. +.##.##..##..# +.#.#.#..##..# + +...#### +...#### +.#..#.. +######. +##.#..# +##.#.## +######. +.#..#.. +...#### + +.....#. +###.##. +##...#. +####.## +####.## +##...#. +###.##. +.....#. +#.##... +###..#. +###.### +....##. +##.#.## + +##.#....# +##.#.##.# +...#....# +..#.####. +....####. +##...##.. +....####. +####.##.. +..#...... +##...##.. +###.####. +#####..## +###..##.. + +..##..### +..##.##.. +..##.##.# +..##..### +##.....## +.....##.. +..##...#. +##.#...#. +##.###..# + +.####...##... +..#....#..#.. +#####.##..##. +#..#.##.##.## +...##.#.##.#. +####...####.. +#.......##... +#..#....##... +####...####.. + +#.##..# +...#### +...#### +#.##..# +...##.. +###.#.. +###..#. +.....## +##.#... +#.#..## +.##...# +.##...# +#.##.## + +.##...##.##.##... +.#.####..##..#### +.#.####..##..#### +.##...##.##.##... +####.##.####.##.# +##.#####....##### +#.###..#....#..## +...##..........## +.#.###.######.### +#.##.####..####.# +..##.....##.....# +.#..#...#..#...#. +#.##...##..##...# +#.#.#.##.##.##.#. +.#..####....####. +#...####.##.###.. +...#..#.####.#..# + +....#.##..#.#.##. +#..##..#..#.#...# +.##.##.#.#..#.##. +.....#....#.#.##. +####.###....#.... +#..#.#.#.#..#.... +#..###.##....#### +####..#....#.#..# +####.#...###.#..# +#####..#.###..... +####.#####.#.#..# +#####.#.###...##. +####.##..#...#### + +.......##...... +....########... +#####.####.#### +##..#.####.#..# +##.##......##.# +....###..###... +...#..#..#..##. + +..........###.. +#.####.##..#... +#.#..#.##.#...# +.######.###..## +...##...##.#### +########..##... +............#.. + +....#.###.#.. +#..#...#...#. +....#.##.#### +....#.##.#### +#..#...#...#. +....#.###.#.. +......##.#### +.###.#####.## +####.#####.## +....#.##....# +....##..#..#. +.##.###....#. +.##....####.. +#####...#.#.. +######.#..### + +.##.### +...#... +###.### +.#..... +#.#.#.. +####... +..##... +##.#... +#...... +.#.##.. +#.#.### +..##### +..##### +..#.### +.#.##.. + +####.#.#### +####.#..##. +#...#.##..# +#...#.##..# +####.#..##. +####.#.#### +#.#...#.... +#.....##..# +#.#.##..##. +.###.#..##. +##...#..... +.###..#.... +.####.#.##. +....#...##. +.####....#. + +....##### +....#.... +####.#..# +.....#### +#..###### +#..#..... +#####.... +###.##### +#####.##. +#..##.... +.##.#.... +####.#### +#..#.#### + +######..##.#.#.## +#.........####... +###.##.....#.##.. +##.#.###..###..## +###..#...#....### +#.#...#.#######.. +.#..#.###.#.##... +.##...####.#..### +.##....#....#.#.. +.#.##.#..#..##### +##....###......## +...##.######..#.. +....#.#..#.###### +##...###..##..### +##.#.###..##..### + +.....###..###.#.. +#####.#...#...... +#####.##.#..#.... +.##.##.#.###.#.## +......#..###.##.. +....#...#.####... +.....####.#.###.. +......#.##.##.#.. +...##.##....#.#.. +#..##.##.###..### +#..#..###.###..## +#..#...#....###.. +....#....##.#..## + +....#.... +##.###### +##.#..... +##.#.#### +##..#...# +..#.#.##. +......##. +###..#### +..##.#..# + +..##..# +##..... +...#### +...#### +##..... +..##..# +#.#.#.. +#.##... +#..##.# +####... +####... +#..##.# +#.##... +..#.#.. +..##..# + +...##.####### +...##.#.##### +#....#..#..## +#..########.. +#.##...#...## +.#....#...#.. +.#....#...#.. +#.##...#...## +#..########.. +#....#..#..## +...##.#.##### +...##.####### +.####.....### +######.#.#..# +..#..#.#.#### +...#..#..#### +..####..###.# + +########. +.......## +.####.#.. +..##...## +#....#.#. +..##....# +######... +.#..#..## +##..###.. +......##. +..##..##. +#.#..##.. +.#..#..## +#....##.# +#....##.# + +######.#### +#.##.###### +.#..#.##..# +...#..##..# +######.#..# +.####...##. +.......#### +######.#..# +#....##.... +.####.#.... +......##### +######.#### +#....##.##. + +.####.###.# +.#..#...... +##..####### +#.##.#..### +#######..## +######.###. +##..##...#. +##..##.#.#. +######.###. + +.##...##..#.# +#..#.#..#.... +.##.##.##..#. +.##..#.#.###. +.....#.#.#... +.##.#.###...# +####..###...# +####..###...# +.##.#.###...# +.....#.#.#... +.##..#.#####. + +#.#.#...### +#.....#.#.. +###.##.##.. +######.#### +####.#.#..# +###..##..#. +.###..#.#.# +.###..#.#.# +###.###..#. +####.#.#..# +######.#### +###.##.##.. +#.....#.#.. +#.#.#...### +####...#### +####...#### +#.#.#...### + +###...#...#.##. +.#######.#.#### +.#######.#.#### +###...#...#.##. +#.#####...#..#. +##..#..##..#..# +#..##.##..##..# + +#..#..#..######.. +#.#.##.#.#.##.#.# +..##..##...##...# +....##........... +.########.#..#.## +#...##...######.. +.#......#.#..#.#. +#.##..##.######.# +....##.....##.... +##......##....##. +...####...#..#... +#.#....#.#.##.#.# +..#.##.#........# +#####.####....### +.###..###.#..#.## +##......##....##. +..#.##.#..####..# + +##.######## +.#..#....#. +####.#..#.# +#.##.#..#.# +.#..#....#. +##.######## +#.#..#..#.. +#..#..##..# +##...####.. +.########## +.#.######## +..###.##.## +.#....##... +##...####.. +##..#....#. +##..######. +..#.##..##. + +.#..#.#.#.###.##. +.#..#.#.#.##..##. +......####....#.. +.#..#...##..####. +######.###...#### +.#..#..#....#.#.# +......##...#..... +#######.#.####### +.#..#..##..##.##. + +.###.#.##...... +.......###.##.# +.##..#..#.#..#. +#..##.####.##.# +####.#..###..## +#..##.....####. +#..#...##.#..#. +....#.....#..#. +####..###...... + +#.#..##.####. +#.#..##.####. +.##..#.#..... +#.###.#..#... +....#.####..# +...#.##..###. +.###..#.#.... +..#....#..... +.#.##..#..##. +.#.##..#..##. +..#....#..... +.###..#.#.... +...#.##..###. +....#.####..# +#.###.#..#... +.##..#.#..... +..#..##.####. + +...######.. +####.#..#.# +.#...#..#.. +#..###.#... +#..###.#... +.#...#..#.. +.###.#..#.# +...######.. +..##..#..#. +..##.##.##. +##.#####..# +....#.###.# +#########.. +#.#...##... +#.#...##... +#########.. +....#.###.# + +##....####..###.. +########..#.##... +########..#.##... +##....####..###.. +........####....# +.#.##.#.##.#..#.# +........##.###### +.##...#....#.###. +.######....#.#..# +.#....#.#..###.#. +.##..##...#...##. + +###.##..... +#..#.###.## +#..#..##... +#.#..#.##.. +.##.###.##. +###....#### +.##..#.#... +.##..#.#... +###....#### +.##.###.##. +#.#..#.##.. +#..#..##... +#..#.###.## +###.##..... +###.##....# + +#..#.....#.####.# +####.#.#..#....#. +#####..#......... +#.#####.##..##..# +#..#.#.#...####.. +#..#.##....####.. +#..#####.###..### +.##.#....#..##..# +#..##.#.##.#..#.# + +##..#..#.##.##.## +##..#..#.##..#.## +.#####..##.##..## +..#.###.###..#..# +..#.###.###..#..# +.#####..##.##..## +##..#..#.##..#.## +##..#..#.##.##.## +#...###..#.##...# +#........#..#.##. +#...#.#...#.##... + +#....##.#.. +#.##.#..### +.####.##..# +.####.##..# +#.##.#...## +#....##.#.. +##..##.#..# + +.#.#..#.#.#.#..## +.##....##..#.#### +####..####..#.#.. +.##.##.##.#...#.# +..######..##..... +..######..##..#.. +.##.##.##.#...#.# + +.####.# +.####.. +.####.# +#....#. +#.##.## +##..### +.####.. + +#..#.#..###...##. +#..#.#..###...##. +#.#.....##.#.##.# +#..#####...#.#.## +##....###......## +##..###.#.###..## +.#....###...#..## +#.###.#...#.....# +##.....#...##.### +......#..######## +##.#############. +.#.#.##.....####. +###.##.###.###..# +####.###..#.#.#.. +#.##.#......#.##. +#####.....#..#..# +#####..#..#..#..# + +.##.####.##....## +####.##.######... +#.#..##..#.#...## +##.#....#..#.#... +...#.##.#....#... +#..........#..... +#.##....##.#..### +#..#.##.#..##.### +............#.### +...#.##.#...#..## +#.##.##.##.#.#... +...#.##.#........ +...######....#... +#.#.####.#.##.#.. +##.#....#.####.## +...#.##.#....#### +.#.#....#.#...### + +...##.##..####. +..##.#.#.#.#### +##.#.#.###.##.. +......#.#####.. +..##..#.####.## +..##...#.#.#... +..#.#.#...#.... +#####.##.##.#.. +##.###.##...... +..#..##..#.##.. +....#....##.#.. +...#.#.#.#.#### +##.#.##.#.##.## +###..#....###.. +..##.#..#.#..## +..##..#.##..### +..#..#.##.###.. + +.....##..#.#.##.# +#..####.#.##..##. +..##..##.#......# +.##.###.###....## +#..#.#..#........ +..##.##..###..### +.##....#.#..##..# +##.#.##.......... +##.#.##.......... + +#..##.... +#....#.#. +##.###.## +.####.### +#.####### +..#.###.. +..#.###.. + +.#.###.#... +#.#.#.#..## +###..#..#.. +#.#..#..#.. +#.#.#.#..## +.#.###.#... +#......#### + +#.#..#..#..#.## +.#.########.#.. +.#...##.#...#.. +.#.#......#.#.. +###...##...#### +.#..........#.. +...#......#.... + +...#.#####.#. +.#.#.....#..# +#.##..#.#.### +#.##..#.#.### +.#.##....#..# +...#.#####.#. +######......# +###.####.#### +..##.###.###. +###......##.. +...##.#....#. +...##.#....#. +###......##.. +..##.###.###. +###.####.#### +######......# +...#.#####.#. + +##.#....#.# +.#.##..##.# +..###...##. +#..######.. +#...#..#... +#..#....#.. +.###.##.### +.####..#### +#.##.##.##. +#..######.. +...#.##.#.. +...#.##.#.. +#..######.. +#.##.##.##. +.####..#### +.###.##.### +#..#....#.. + +####.#.####.####. +#.#.#..######..## +.##.##.....#....# +.##.####...###### +...#..#.#.###..## +.####.###.###..## +#.##..#.#....##.. +#....##.#..###### +#....###..##.##.# +#....####.##.##.# +#....##.#..###### +#.##..#.#....##.. +.####.###.###..## +...#..#.#.###..## +.##.####...###### +.##.##.....#....# +#.#.#..######..## + +.#.####.#.#.... +.#.####.#.#.... +.##......##...# +.#...#....#.#.. +###..#.#..#.#.# +####....#.##..# +.#.#..##.#.##.# +.##....###..#.# +..##.##.##...#. +.#.#.....#....# +.#.#.....#....# +..##.##.##...#. +.##....###..#.# +.#.#..##.#.##.# +####....#.#...# + +....#.. +#.##..# +#####.. +.##.##. +####.## +####.## +#..###. +#..##.. +#####.. +.....## +.....## + +##.#....#..#...#. +####..#..#####... +####..#..#####... +##.#....#..#...#. +####.##.#.#.#...# +#####....##.####. +.#####..###.#..#. +######.##...#.#.. +...###.....#.#### +###.##..##..####. +..#.##.......#### + +##.#..#.#.# +##.##.#.#.# +####.#..#.# +..##.####.. +##.####.#.. +....##..#.# +..##.###.#. +#####.###.. +######....# +##.#####.## +..#.##.#.#. + +.##...# +....### +####.## +####.## +....### +.##...# +.....#. +#..#... +.##.#.. +...##.# +....#.. + +#######..#### +####.##..#... +#..##..#...#. +.#####....### +.##.....##... +....#.###..## +#..#..##..##. +........###.# +........###.# + +####...## +###..#... +###.##... +####...## +#.#..#..# +#.###.... +....##.## +.#...#### +#.#..#..# +###....## +.....##.. +.....##.. +###....## + +#.#...#..#... +...##.####.## +...##.####.## +#.....#..#... +.##..##..##.. +...#...##...# +#...#.####.#. +##...#.##.#.. +#..##......## +#.##...##...# +##....####... + +#..###.## +#..#.#.## +..##.###. +..##.#.## +##...##.# +##...##.# +..##.#.## +..##.###. +#..#.#.## +#..###.## +.###..#.# + +...#.###....# +..#.###.####. +.#.#..####### +.#####.#.##.. +#.#.#.#..##.. +##.###....... +##.###....... + +#.##..##.##.# +...####...... +#..####..##.. +##.####.####. +####..####### +##..##..####. +##..##..####. +#..#..#..##.. +..##..##....# +..#....#....# +...#..#...... +.##..#.##..## +.#..##..#..#. +#.#.##.#.##.# +.########..## + +##....##.#### +.#...##.###.. +.#.#.....#.#. +.##..#.#.#.## +.....#.##.#.# +.....#.##.#.# +.##..#.#.#.## +.#.##....#.#. +.#...##.###.. +##....##.#### +.############ +..####.###.## +..####.###.## +.############ +##....##.#### From 9f7c2a6448b84b0fdf683c50e4f1f7b02b28991b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 13 Dec 2023 10:08:35 +0000 Subject: [PATCH 2/4] 2023: d13: ex1: add solution --- 2023/d13/ex1/ex1.py | 84 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 2023/d13/ex1/ex1.py diff --git a/2023/d13/ex1/ex1.py b/2023/d13/ex1/ex1.py new file mode 100755 index 0000000..a591a9e --- /dev/null +++ b/2023/d13/ex1/ex1.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +import sys +from typing import NamedTuple, Optional + + +class Point(NamedTuple): + x: int + y: int + + +class Grid(NamedTuple): + points: set[Point] + lines: int + rows: int + + +def solve(input: str) -> int: + def parse_grid(grid: list[str]) -> Grid: + points: set[Point] = set() + + for x, line in enumerate(grid): + for y, c in enumerate(line): + if c != "#": + continue + points.add(Point(x, y)) + + return Grid(points, len(grid), len(grid[0])) + + def parse(input: str) -> list[Grid]: + return [parse_grid(grid.splitlines()) for grid in input.split("\n\n")] + + def reflect_vertical(grid: Grid) -> Optional[int]: + def try_row(row: int) -> bool: + for y in range(min(row, grid.rows - row)): + for x in range(grid.lines): + left = Point(x, row - y - 1) in grid.points + right = Point(x, row + y) in grid.points + if left and right: + continue + if left or right: + return False + return True + + for row in range(1, grid.rows): + if try_row(row): + return row + return None + + def reflect_horizontal(grid: Grid) -> Optional[int]: + def try_line(line: int) -> bool: + for x in range(min(line, grid.lines - line)): + for y in range(grid.rows): + up = Point(line - x - 1, y) in grid.points + down = Point(line + x, y) in grid.points + if up and down: + continue + if up or down: + return False + return True + + for line in range(1, grid.lines): + if try_line(line): + return line + return None + + def solve(grid: Grid) -> int: + if (columns := reflect_vertical(grid)) is not None: + return columns + if (rows := reflect_horizontal(grid)) is not None: + return 100 * rows + assert False # Sanity check + + grids = parse(input) + return sum(map(solve, grids)) + + +def main() -> None: + input = sys.stdin.read() + print(solve(input)) + + +if __name__ == "__main__": + main() From 21986b1148fd3d6ad28e93f842ab960aaf576b0e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 13 Dec 2023 10:08:42 +0000 Subject: [PATCH 3/4] 2023: d13: ex2: add input --- 2023/d13/ex2/input | 1349 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1349 insertions(+) create mode 100644 2023/d13/ex2/input diff --git a/2023/d13/ex2/input b/2023/d13/ex2/input new file mode 100644 index 0000000..6d7d1e2 --- /dev/null +++ b/2023/d13/ex2/input @@ -0,0 +1,1349 @@ +######..# +.##....#. +.....##.# +.....##.# +.##..#.#. +######..# +#..#..### +.##..#.## +#####.#.# +#..#.##.. +.....###. +#####.... +....##.#. + +##..###.###.. +##.#.#..##..# +..#.#...#.#.# +######.#.#### +##..#.##....# +##.##.#..#.#. +#####....#.#. +###.########. +#######..#.## +..####..##..# +......#.###.. +......#.###.. +..####..#...# + +....#....##..##.. +##.#.....#....#.. +....##...#.##.#.. +..##..#####..#### +###..##..######.. +.....##.#.#..#.#. +.#.#####.##..##.# +###.###...####... +....####.#....#.# + +#.##.#.####.# +.#..#..#..#.. +.####.#....#. +#....#......# +.#..#.#....#. +.##.#.######. +#....######## +#....##....## +########..### +.#..#..####.. +.#..#..####.. +..##....##... +.####...##... +.#..#.##..##. +##..######### + +#.##.#.## +#....##.. +.......## +#....##.. +#....#### +#.####.## +.####.### + +.###.#### +.##.##..# +.###.#### +#....#..# +....#.... +##.##.... +##.###..# +#..#..##. +.#...#..# +....#.... +##.###### +...###.## +#.###.... +##.#.#### +##.#.#### + +......##.## +####..###.. +.##....#.#. +######.#### +######.#### +.##....#.#. +####..###.. +......##.## +.##.##.##.# +...##..###. +....###.##. +#..#......# +....##..... +#####.#.#.. +.....#..##. + +###.....###..## +#.#..#..##...## +..##.#...###.## +..##.#...##..## +#.#..#..##...## +###.....###..## +.##.#...#.#...# +##...#####.###. +##.#...###....# +#.####..#.#.#.. +#.##..###.###.. +#.##..###.###.. +#.####..#.#.#.. +##.#...###....# +##...#####.###. + +..###..#....#.. +##.....#.##.#.. +###....#.##.#.. +###.#..#....#.. +..##.#........# +####........... +..##...##..##.. +##...#.######.# +..#.#.########. +##....#.####.#. +##.#.####...### +##...#.#....#.# +##...##.#..#.## + +##..#..#..##..# +.###....###.#.. +.#...##...#..#. +..##.##.##..... +.#.#.##.#.#.#.# +.....#........# +.#..####..#.##. +####.##.####.## +####.##.####.## + +.#.#..####. +#.####.##.# +..#..###### +..#...####. +..#...####. +..#..###### +#.####.##.# +.#.#..####. +#..#.##..## +#.#.####### +###........ +....##....# +..#.###..## +...#..#.##. +.#.#.##..## + +##...#...##.#.#.# +##.#.......#.#.## +##.#.......#.#.## +##.......##.#.#.# +###....#.##.#...# +.#.#.#..#.###.##. +.#...#..##....... +#..#.#....#.##.## +.#.##...###.#..## +.##.#.#.#.#...### +#...##..#...#.##. +.#.####...#..#.## +.#.####...#..#.## +#...##..#...#.##. +.##.#.#.#.#...### + +.....#.##..##.# +.....#.##..##.# +.##.##.##..##.. +....#..#....#.. +#..#.###....### +##..#.##.##.##. +#...##........# +.#..#.###..###. +..##...#....#.. +#....#.##..##.# +#.##..###..###. + +.##.....#..#. +.##..#.###### +#.#...#...... +.###..#...... +..#..#..#..#. +..#..#..#..#. +.###.##...... +#.#...#...... +.##..#.###### +.##.....#..#. +........####. +.####.##....# +.#.##.#...... +######..####. +.#.##..##..## +....##.#....# +.###.#.###### + +###.#.####.#. +###.#.####.#. +...#.#.##.#.# +###...#..#... +.#.#.#....#.# +##..#..#...#. +..###..##..## +####..#..#..# +#...#......#. +..##..####..# +.#..########. +.#.#.#....#.# +#..####..#### +.#........... +#.#.#.#..#.#. + +#.#.... +#.#.... +#..#..# +..##..# +#...... +#...... +..#.##. +#.#.##. +#.##... +..#.##. +#.#.##. +#.##### +#.##### +.#.#### +##..##. + +.##.....### +#..###.##.# +.##..#.##.. +.....#.#.#. +#..##.#..## +#..##.#..## +.....#.#.#. +.##..#.##.. +#..###.##.# +.##..#..### +#..##..##.# +####...##.# +#..#.#.#.#. +........#.# +....####... +....#.###.# +.##.#.#..#. + +###.######. +...##.##.## +.###.#..#.# +....######. +.#.######## +#####....## +..##..##..# +#.##..##..# +##....##... +.#..#...... +#####....## +##....##... +.##.######. +###..####.. +....#.##.#. +....#.##.#. +###..####.. + +#.####..####.##.. +##..##..##..##.## +.#....##....###.. +###...##...###.## +#.#........#.#.## +.#.##....##.#.### +.#..........#.... +.#..........#.### +##.##.##.##.##### +##..........##### +.#..........#.### +.#####..#####.... +#..##....##..##.. + +#.##.#.#### +.###.###### +#..#....##. +#...####### +##.##..#..# +...#.###### +#.##....... +.#......... +##.####.##. +#..####.##. +.#......... +#.##....... +...#.###### +##.##..#..# +#...####### +#..#....##. +.###.###### + +.#...###... +.....##.### +..#..##.#.. +####....... +..##..#.##. +######.###. +########..# +########..# +######.###. +..##..#.##. +####....... + +##....###.. +###..####.. +..#..#..##. +...##...#.# +.#.##.#.##. +##.##.####. +########.## +..#..#..##. +########.#. +##.##.##... +...##...### +#########.. +...##....## + +#.....###.... +#.##.####.##. +#..#..##..#.. +##...#..#...# +.....#..#.... +####..##..### +..##......##. +##..######..# +##.##....##.# +##.##....##.# +##..######..# + +.####.##.#.#..##. +.....######..#..# +..#..######..#..# +.####.##.#.#..##. +######..##...#### +#..##.#..#.###### +..#....#.##...... +.##.#..###...#### +.....#..#..##.... +##.#..##.###..##. +#..##.#.##.#.#..# +..##.#.##...##..# +####.......#..... +.###.####...##..# +#..#..#.#####.... +###.#.#..###..... +####...######.... + +#####.###...# +##..#.#.###.. +#..#..##..#.# +##...##.#..#. +#####....##.# +.....##...### +#####.#.#.### +#####.#.#.### +.....##...### + +..##### +.#..... +.###### +#..#### +.###### +..#.... +###.... +###.... +##.#### +..#.##. +.#.#### +.###### +.#.#### +#.##### +##..... + +####....#...#.### +.#..#..####.##..# +.##.##.##..#####. +......##.##.##### +###.#.##.#####.## +.####....#...#### +.##.#....#...#### +###.#.##.#####.## +......##.##.##### +.##.##.##..#####. +.#..#..####.##..# +####....#...#.### +####....#...#.### + +###...#..#...## +...#......#.#.. +....#......#... +##..#.####.#..# +##..#.#..#.#..# +##.#.######.#.# +....#.####.#... +..##.#.##.#.##. +##...######...# +###.#..##..#.## +..#..######..#. + +.##..##..##..#### +####.##.####..... +.###.##.###..#### +..#.#..#.#...#### +.............#..# +...######...#.##. +..#.#..#.#..####. + +##.##.#.# +###.#.#.# +###.#.#.# +##.####.# +...#####. +...###### +...#..### +..######. +##...##.# +##...#..# +#####.#.. + +#.###.. +####.## +.#.##.. +....### +.##.... +.##.... +.#..### + +......#....#..... +#..#.########.#.. +.##.##......##.## +....#.######.#.#. +.#..##########..# +#.#..###..###..#. +####..######..### +#.##..#.##.#..##. +#..#..######..#.. +.#.#..##..##..#.# +#.#...#.##.#...#. +.#.##.#.##.#.##.# +.#.##.#.##.#.##.# + +###..## +#....## +###..#. +##..... +..#..## +#....## +#...### +###.### +..##.## +...##.. +...##.. +..##... +##.#... +..#.... +.##.### +###.... +###.... + +####.###..# +.......###. +......####. +####.###..# +###..#.#### +###.#....## +..#.#.....# +###.##.#.## +##.###.###. +####.##.#.. +##..#.#.#.. + +#..##.....##. +.......#..#.# +.##..#...#.## +.##..#...#.## +.......#..#.# +#..##.....##. +.##..#.###### +######.##.... +####...##.... +....#.##.#.## +#.....####... +.##..###..... +#####..#....# + +#..####..#... +####..#####.. +###....###.#. +..#....#..#.. +.#.#..#.#.### +.###..###.... +###########.. +#...##...#.## +...........## +..#....#...## +#.#....#.#### + +.##...#.# +.##..#... +.##.###.. +.##..#.#. +.##....## +#####.##. +.##...### +#..#..#.# +#..#..#.# +.##...### +########. +.##....## +.##..#.#. +.##.###.. +.##..#... + +.##.#....###..# +.##.#....###..# +..#######...... +.######.#.##.## +..#.#..#...###. +##....#.#.###.. +##....#.#.###.. +..#.#..#...###. +.######.#.##.#. +..#######...... +.##.#....###..# + +.##..####.. +.##..####.. +###...##... +...###..### +..#.#.##.#. +...######.# +...#..##..# +...#.#..#.# +#.#.##..##. + +##.#......... +#.####..##..# +##.#.######## +##.##........ +##.########## +#.#.......... +.#.#......... +#.########### +.###.#......# +###.......... +#.#.#.##..##. +.#....##..##. +#.#...##..##. +.##.##..##..# +.#.#.#..##..# + +...#### +...#### +.#..#.. +######. +##.#..# +##.#.## +######. +.#..#.. +...#### + +.....#. +###.##. +##...#. +####.## +####.## +##...#. +###.##. +.....#. +#.##... +###..#. +###.### +....##. +##.#.## + +##.#....# +##.#.##.# +...#....# +..#.####. +....####. +##...##.. +....####. +####.##.. +..#...... +##...##.. +###.####. +#####..## +###..##.. + +..##..### +..##.##.. +..##.##.# +..##..### +##.....## +.....##.. +..##...#. +##.#...#. +##.###..# + +.####...##... +..#....#..#.. +#####.##..##. +#..#.##.##.## +...##.#.##.#. +####...####.. +#.......##... +#..#....##... +####...####.. + +#.##..# +...#### +...#### +#.##..# +...##.. +###.#.. +###..#. +.....## +##.#... +#.#..## +.##...# +.##...# +#.##.## + +.##...##.##.##... +.#.####..##..#### +.#.####..##..#### +.##...##.##.##... +####.##.####.##.# +##.#####....##### +#.###..#....#..## +...##..........## +.#.###.######.### +#.##.####..####.# +..##.....##.....# +.#..#...#..#...#. +#.##...##..##...# +#.#.#.##.##.##.#. +.#..####....####. +#...####.##.###.. +...#..#.####.#..# + +....#.##..#.#.##. +#..##..#..#.#...# +.##.##.#.#..#.##. +.....#....#.#.##. +####.###....#.... +#..#.#.#.#..#.... +#..###.##....#### +####..#....#.#..# +####.#...###.#..# +#####..#.###..... +####.#####.#.#..# +#####.#.###...##. +####.##..#...#### + +.......##...... +....########... +#####.####.#### +##..#.####.#..# +##.##......##.# +....###..###... +...#..#..#..##. + +..........###.. +#.####.##..#... +#.#..#.##.#...# +.######.###..## +...##...##.#### +########..##... +............#.. + +....#.###.#.. +#..#...#...#. +....#.##.#### +....#.##.#### +#..#...#...#. +....#.###.#.. +......##.#### +.###.#####.## +####.#####.## +....#.##....# +....##..#..#. +.##.###....#. +.##....####.. +#####...#.#.. +######.#..### + +.##.### +...#... +###.### +.#..... +#.#.#.. +####... +..##... +##.#... +#...... +.#.##.. +#.#.### +..##### +..##### +..#.### +.#.##.. + +####.#.#### +####.#..##. +#...#.##..# +#...#.##..# +####.#..##. +####.#.#### +#.#...#.... +#.....##..# +#.#.##..##. +.###.#..##. +##...#..... +.###..#.... +.####.#.##. +....#...##. +.####....#. + +....##### +....#.... +####.#..# +.....#### +#..###### +#..#..... +#####.... +###.##### +#####.##. +#..##.... +.##.#.... +####.#### +#..#.#### + +######..##.#.#.## +#.........####... +###.##.....#.##.. +##.#.###..###..## +###..#...#....### +#.#...#.#######.. +.#..#.###.#.##... +.##...####.#..### +.##....#....#.#.. +.#.##.#..#..##### +##....###......## +...##.######..#.. +....#.#..#.###### +##...###..##..### +##.#.###..##..### + +.....###..###.#.. +#####.#...#...... +#####.##.#..#.... +.##.##.#.###.#.## +......#..###.##.. +....#...#.####... +.....####.#.###.. +......#.##.##.#.. +...##.##....#.#.. +#..##.##.###..### +#..#..###.###..## +#..#...#....###.. +....#....##.#..## + +....#.... +##.###### +##.#..... +##.#.#### +##..#...# +..#.#.##. +......##. +###..#### +..##.#..# + +..##..# +##..... +...#### +...#### +##..... +..##..# +#.#.#.. +#.##... +#..##.# +####... +####... +#..##.# +#.##... +..#.#.. +..##..# + +...##.####### +...##.#.##### +#....#..#..## +#..########.. +#.##...#...## +.#....#...#.. +.#....#...#.. +#.##...#...## +#..########.. +#....#..#..## +...##.#.##### +...##.####### +.####.....### +######.#.#..# +..#..#.#.#### +...#..#..#### +..####..###.# + +########. +.......## +.####.#.. +..##...## +#....#.#. +..##....# +######... +.#..#..## +##..###.. +......##. +..##..##. +#.#..##.. +.#..#..## +#....##.# +#....##.# + +######.#### +#.##.###### +.#..#.##..# +...#..##..# +######.#..# +.####...##. +.......#### +######.#..# +#....##.... +.####.#.... +......##### +######.#### +#....##.##. + +.####.###.# +.#..#...... +##..####### +#.##.#..### +#######..## +######.###. +##..##...#. +##..##.#.#. +######.###. + +.##...##..#.# +#..#.#..#.... +.##.##.##..#. +.##..#.#.###. +.....#.#.#... +.##.#.###...# +####..###...# +####..###...# +.##.#.###...# +.....#.#.#... +.##..#.#####. + +#.#.#...### +#.....#.#.. +###.##.##.. +######.#### +####.#.#..# +###..##..#. +.###..#.#.# +.###..#.#.# +###.###..#. +####.#.#..# +######.#### +###.##.##.. +#.....#.#.. +#.#.#...### +####...#### +####...#### +#.#.#...### + +###...#...#.##. +.#######.#.#### +.#######.#.#### +###...#...#.##. +#.#####...#..#. +##..#..##..#..# +#..##.##..##..# + +#..#..#..######.. +#.#.##.#.#.##.#.# +..##..##...##...# +....##........... +.########.#..#.## +#...##...######.. +.#......#.#..#.#. +#.##..##.######.# +....##.....##.... +##......##....##. +...####...#..#... +#.#....#.#.##.#.# +..#.##.#........# +#####.####....### +.###..###.#..#.## +##......##....##. +..#.##.#..####..# + +##.######## +.#..#....#. +####.#..#.# +#.##.#..#.# +.#..#....#. +##.######## +#.#..#..#.. +#..#..##..# +##...####.. +.########## +.#.######## +..###.##.## +.#....##... +##...####.. +##..#....#. +##..######. +..#.##..##. + +.#..#.#.#.###.##. +.#..#.#.#.##..##. +......####....#.. +.#..#...##..####. +######.###...#### +.#..#..#....#.#.# +......##...#..... +#######.#.####### +.#..#..##..##.##. + +.###.#.##...... +.......###.##.# +.##..#..#.#..#. +#..##.####.##.# +####.#..###..## +#..##.....####. +#..#...##.#..#. +....#.....#..#. +####..###...... + +#.#..##.####. +#.#..##.####. +.##..#.#..... +#.###.#..#... +....#.####..# +...#.##..###. +.###..#.#.... +..#....#..... +.#.##..#..##. +.#.##..#..##. +..#....#..... +.###..#.#.... +...#.##..###. +....#.####..# +#.###.#..#... +.##..#.#..... +..#..##.####. + +...######.. +####.#..#.# +.#...#..#.. +#..###.#... +#..###.#... +.#...#..#.. +.###.#..#.# +...######.. +..##..#..#. +..##.##.##. +##.#####..# +....#.###.# +#########.. +#.#...##... +#.#...##... +#########.. +....#.###.# + +##....####..###.. +########..#.##... +########..#.##... +##....####..###.. +........####....# +.#.##.#.##.#..#.# +........##.###### +.##...#....#.###. +.######....#.#..# +.#....#.#..###.#. +.##..##...#...##. + +###.##..... +#..#.###.## +#..#..##... +#.#..#.##.. +.##.###.##. +###....#### +.##..#.#... +.##..#.#... +###....#### +.##.###.##. +#.#..#.##.. +#..#..##... +#..#.###.## +###.##..... +###.##....# + +#..#.....#.####.# +####.#.#..#....#. +#####..#......... +#.#####.##..##..# +#..#.#.#...####.. +#..#.##....####.. +#..#####.###..### +.##.#....#..##..# +#..##.#.##.#..#.# + +##..#..#.##.##.## +##..#..#.##..#.## +.#####..##.##..## +..#.###.###..#..# +..#.###.###..#..# +.#####..##.##..## +##..#..#.##..#.## +##..#..#.##.##.## +#...###..#.##...# +#........#..#.##. +#...#.#...#.##... + +#....##.#.. +#.##.#..### +.####.##..# +.####.##..# +#.##.#...## +#....##.#.. +##..##.#..# + +.#.#..#.#.#.#..## +.##....##..#.#### +####..####..#.#.. +.##.##.##.#...#.# +..######..##..... +..######..##..#.. +.##.##.##.#...#.# + +.####.# +.####.. +.####.# +#....#. +#.##.## +##..### +.####.. + +#..#.#..###...##. +#..#.#..###...##. +#.#.....##.#.##.# +#..#####...#.#.## +##....###......## +##..###.#.###..## +.#....###...#..## +#.###.#...#.....# +##.....#...##.### +......#..######## +##.#############. +.#.#.##.....####. +###.##.###.###..# +####.###..#.#.#.. +#.##.#......#.##. +#####.....#..#..# +#####..#..#..#..# + +.##.####.##....## +####.##.######... +#.#..##..#.#...## +##.#....#..#.#... +...#.##.#....#... +#..........#..... +#.##....##.#..### +#..#.##.#..##.### +............#.### +...#.##.#...#..## +#.##.##.##.#.#... +...#.##.#........ +...######....#... +#.#.####.#.##.#.. +##.#....#.####.## +...#.##.#....#### +.#.#....#.#...### + +...##.##..####. +..##.#.#.#.#### +##.#.#.###.##.. +......#.#####.. +..##..#.####.## +..##...#.#.#... +..#.#.#...#.... +#####.##.##.#.. +##.###.##...... +..#..##..#.##.. +....#....##.#.. +...#.#.#.#.#### +##.#.##.#.##.## +###..#....###.. +..##.#..#.#..## +..##..#.##..### +..#..#.##.###.. + +.....##..#.#.##.# +#..####.#.##..##. +..##..##.#......# +.##.###.###....## +#..#.#..#........ +..##.##..###..### +.##....#.#..##..# +##.#.##.......... +##.#.##.......... + +#..##.... +#....#.#. +##.###.## +.####.### +#.####### +..#.###.. +..#.###.. + +.#.###.#... +#.#.#.#..## +###..#..#.. +#.#..#..#.. +#.#.#.#..## +.#.###.#... +#......#### + +#.#..#..#..#.## +.#.########.#.. +.#...##.#...#.. +.#.#......#.#.. +###...##...#### +.#..........#.. +...#......#.... + +...#.#####.#. +.#.#.....#..# +#.##..#.#.### +#.##..#.#.### +.#.##....#..# +...#.#####.#. +######......# +###.####.#### +..##.###.###. +###......##.. +...##.#....#. +...##.#....#. +###......##.. +..##.###.###. +###.####.#### +######......# +...#.#####.#. + +##.#....#.# +.#.##..##.# +..###...##. +#..######.. +#...#..#... +#..#....#.. +.###.##.### +.####..#### +#.##.##.##. +#..######.. +...#.##.#.. +...#.##.#.. +#..######.. +#.##.##.##. +.####..#### +.###.##.### +#..#....#.. + +####.#.####.####. +#.#.#..######..## +.##.##.....#....# +.##.####...###### +...#..#.#.###..## +.####.###.###..## +#.##..#.#....##.. +#....##.#..###### +#....###..##.##.# +#....####.##.##.# +#....##.#..###### +#.##..#.#....##.. +.####.###.###..## +...#..#.#.###..## +.##.####...###### +.##.##.....#....# +#.#.#..######..## + +.#.####.#.#.... +.#.####.#.#.... +.##......##...# +.#...#....#.#.. +###..#.#..#.#.# +####....#.##..# +.#.#..##.#.##.# +.##....###..#.# +..##.##.##...#. +.#.#.....#....# +.#.#.....#....# +..##.##.##...#. +.##....###..#.# +.#.#..##.#.##.# +####....#.#...# + +....#.. +#.##..# +#####.. +.##.##. +####.## +####.## +#..###. +#..##.. +#####.. +.....## +.....## + +##.#....#..#...#. +####..#..#####... +####..#..#####... +##.#....#..#...#. +####.##.#.#.#...# +#####....##.####. +.#####..###.#..#. +######.##...#.#.. +...###.....#.#### +###.##..##..####. +..#.##.......#### + +##.#..#.#.# +##.##.#.#.# +####.#..#.# +..##.####.. +##.####.#.. +....##..#.# +..##.###.#. +#####.###.. +######....# +##.#####.## +..#.##.#.#. + +.##...# +....### +####.## +####.## +....### +.##...# +.....#. +#..#... +.##.#.. +...##.# +....#.. + +#######..#### +####.##..#... +#..##..#...#. +.#####....### +.##.....##... +....#.###..## +#..#..##..##. +........###.# +........###.# + +####...## +###..#... +###.##... +####...## +#.#..#..# +#.###.... +....##.## +.#...#### +#.#..#..# +###....## +.....##.. +.....##.. +###....## + +#.#...#..#... +...##.####.## +...##.####.## +#.....#..#... +.##..##..##.. +...#...##...# +#...#.####.#. +##...#.##.#.. +#..##......## +#.##...##...# +##....####... + +#..###.## +#..#.#.## +..##.###. +..##.#.## +##...##.# +##...##.# +..##.#.## +..##.###. +#..#.#.## +#..###.## +.###..#.# + +...#.###....# +..#.###.####. +.#.#..####### +.#####.#.##.. +#.#.#.#..##.. +##.###....... +##.###....... + +#.##..##.##.# +...####...... +#..####..##.. +##.####.####. +####..####### +##..##..####. +##..##..####. +#..#..#..##.. +..##..##....# +..#....#....# +...#..#...... +.##..#.##..## +.#..##..#..#. +#.#.##.#.##.# +.########..## + +##....##.#### +.#...##.###.. +.#.#.....#.#. +.##..#.#.#.## +.....#.##.#.# +.....#.##.#.# +.##..#.#.#.## +.#.##....#.#. +.#...##.###.. +##....##.#### +.############ +..####.###.## +..####.###.## +.############ +##....##.#### From d8f472ec43b95f89deec642e877ade735662feb6 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 13 Dec 2023 10:08:47 +0000 Subject: [PATCH 4/4] 2023: d13: ex2: add solution --- 2023/d13/ex2/ex2.py | 86 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 2023/d13/ex2/ex2.py diff --git a/2023/d13/ex2/ex2.py b/2023/d13/ex2/ex2.py new file mode 100755 index 0000000..febde9b --- /dev/null +++ b/2023/d13/ex2/ex2.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python + +import sys +from typing import NamedTuple, Optional + + +class Point(NamedTuple): + x: int + y: int + + +class Grid(NamedTuple): + points: set[Point] + lines: int + rows: int + + +def solve(input: str) -> int: + def parse_grid(grid: list[str]) -> Grid: + points: set[Point] = set() + + for x, line in enumerate(grid): + for y, c in enumerate(line): + if c != "#": + continue + points.add(Point(x, y)) + + return Grid(points, len(grid), len(grid[0])) + + def parse(input: str) -> list[Grid]: + return [parse_grid(grid.splitlines()) for grid in input.split("\n\n")] + + def reflect_vertical(grid: Grid) -> Optional[int]: + def try_row(row: int) -> set[Point]: + smudges: set[Point] = set() + for y in range(min(row, grid.rows - row)): + for x in range(grid.lines): + left = Point(x, row - y - 1) in grid.points + right = Point(x, row + y) in grid.points + if left and right: + continue + if left or right: + smudges.add(Point(x, row - y - 1)) + return smudges + + for row in range(1, grid.rows): + if len(try_row(row)) == 1: + return row + return None + + def reflect_horizontal(grid: Grid) -> Optional[int]: + def try_line(line: int) -> set[Point]: + smudges: set[Point] = set() + for x in range(min(line, grid.lines - line)): + for y in range(grid.rows): + up = Point(line - x - 1, y) in grid.points + down = Point(line + x, y) in grid.points + if up and down: + continue + if up or down: + smudges.add(Point(line - x - 1, y)) + return smudges + + for line in range(1, grid.lines): + if len(try_line(line)) == 1: + return line + return None + + def solve(grid: Grid) -> int: + if (columns := reflect_vertical(grid)) is not None: + return columns + if (rows := reflect_horizontal(grid)) is not None: + return 100 * rows + assert False # Sanity check + + grids = parse(input) + return sum(map(solve, grids)) + + +def main() -> None: + input = sys.stdin.read() + print(solve(input)) + + +if __name__ == "__main__": + main()