From 4154f45f8fadfc011150370cf4c926ae503428f0 Mon Sep 17 00:00:00 2001 From: plasmaofthedawn Date: Sat, 23 Dec 2023 00:05:29 -0500 Subject: [PATCH] day 13 --- Makefile | 10 + resources/day13.txt | 1350 +++++++++++++++++++++++++++++++++++++++++++ src/day13/part1.pas | 142 +++++ src/day13/part2.pas | 149 +++++ 4 files changed, 1651 insertions(+) create mode 100644 resources/day13.txt create mode 100644 src/day13/part1.pas create mode 100644 src/day13/part2.pas diff --git a/Makefile b/Makefile index e403b7d..8fe1ec7 100644 --- a/Makefile +++ b/Makefile @@ -118,6 +118,16 @@ day12part2: @echo ./build/day12part2 +day13part1: + fpc src/day13/part1.pas -obuild/day13part1 + @echo + ./build/day13part1 + +day13part2: + fpc src/day13/part2.pas -obuild/day13part2 + @echo + ./build/day13part2 + clean: rm build/* \ No newline at end of file diff --git a/resources/day13.txt b/resources/day13.txt new file mode 100644 index 0000000..7db1c8f --- /dev/null +++ b/resources/day13.txt @@ -0,0 +1,1350 @@ +.###...## +##..#.... +##..#..#. +......### +#..##..## +######.#. +.#.###..# +#####.#.# +##..#..## +##..#..## +#####.#.# +.#.###..# +######.#. +#..##..## +......### +##..#..#. +##..#.... + +.#....#..#... +#..##..##.... +...##...#.##. +...##...###.# +.##..##.#.#.# +.##..##.#.### +...##...###.# + +....#.##..##. +....##......# +.##.##......# +#..####.##.## +####....##... +#..##..#..#.. +.##.####..### +#..###..##..# +####..#.##.#. +....###....## +.....#..##..# +.....##...### +....#.#....#. + +.######..##..## +.#.##.#.####.## +.#.##.#.####..# +.######..##..## +.#....#.#..#.## +########...#... +..####......... +..#..#..##.###. +#.#..#.#..####. + +..#.#.##.##.# +##.#.#.#..##. +....##..##.#. +..#..###...#. +#.###..#....# +..###..#.#.## +#..#.####..## +....#.######. +#.##.....#.#. +..##.######## +..##.##.##### +###.##.####.. +###.##.####.. +..##.##.##### +..##.######## + +#.####### +....##### +..##..... +.#.###### +.#..#.... +#........ +..#...##. +#.###.... +###.##..# +.######## +#.##.#..# +.#.###..# +..###.... +..###.... +...###..# + +#.##.######.##.## +###...####...#### +....##.##.##..... +#..#.#....#.#..## +.....##..##...... +#.#.###..###.#.## +.##.#.####.#.#... +.#..#......#..#.. +.####.####.####.. +###...####...#### +#.##........##.## +.#....#..#....#.. +..###.####.###... + +.##.#.....#.. +......#...### +.##..#..#.... +.##.##..#.... +.......#...## +.##..#.##...# +.....####..## +#..#.#..##### +####.#.#.#### +.##.#.##..#.. +.##.#####.#.. +#..#.##..##.. +####.###..#.. + +##.#...#..# +##.#...#..# +###....#..# +####.####.# +.###..#.##. +###...##.## +#...###.#.. +#...###.#.. +###...##.## +.###..#.##. +####.####.# +###....#..# +##.##..#..# + +.#.##..#..###.### +#..#..##.######## +..##..#.#...##### +.#...#..##....##. +#.####......##.## +#.#...##.#.###... +#.#...##.#.###... + +.#..###..###..# +.#..#.####.#..# +#.##.##..##.##. +..##.#.##.#.##. +##..##....##..# +#.##...##...##. +..##..#..#..##. +#.##..####..##. +#....##..##.... +.############## +###.###..###.## +#####.#..#.#### +#######..###### +.#..#.####.#..# +#....#.##.#.... + +....#..########.. +...#....######... +.......#.####.#.. +####.##.#.##.#.## +.##.##..#....#..# +..#.####..##..### +...#..#..#..#..#. + +##..##..######. +##..##..##..##. +#.#.##.#.#..#.# +###....######## +##.......####.. +.##....##....## +.#.#..#.#....#. +####..######### +###.##.###..### +.########....## +..######..##..# + +###.............. +.######.####.#### +.#..##.######.##. +##.....#.##.#.... +..#####.#..#.#### +#.#....######.... +##..##.######.##. +###.##..#..#..##. +...############## +.#....#.#..#.#... +#.#.............. + +#.##.#...##...# +#############.# +#.##.#.#....#.# +..##..##....##. +..##..########. +#.##.#..#..#..# +.#..#.###..###. +.####.#......#. +#.##.#.##..##.# +........#..#... +.####..######.. +........#..#... +........####... +.####.##....##. +..##..##....##. + +#.##....##.#. +#....##....#. +###......###. +###......###. +#....##....#. +#.##....##.#. +#.#......#.## +.#..####....# +.#...##...#.# +.##......##.# +...######...# +###.####.###. +...######...# +##.##..##.### +.####..####.. + +..###..#..#...# +..###..#..#...# +#.##..##..#.#.# +..#..#....##..# +##..##.##.##### +....####.#....# +##..#..#.##...# +.#...#####..##. +.#...#####..##. +##..#..#.##.#.# +....####.#....# + +...##.#..## +..#.##.#### +..#.###.... +######.##.. +...#.#..#.. +...#.....#. +##..#...### + +#....##..####.. +......#.##..##. +.####..#####..# +#######.##..##. +.#..#...######. +##..##..#..#..# +##..##..#..#..# +.#..#...######. +#######.##..### +.####..#####..# +......#.##..##. +#....##..####.. +#....###..#.### +#....#.##...#.. +.#..#..##..##.# +##..#######..#. +.####...#.##..# + +...#.#... +###....#. +..###.### +...##.### +###....#. +...#.#... +###....## +###..#... +##....##. +..#.#.#.. +####.##.# +..#####.. +##.##.##. +##.#.#..# +....##..# + +#...#.##. +#.#..#### +....##### +##.#..... +.##.##..# +.##.##### +.#.#..##. +#...#.... +.#.#..... +.####.##. +.####.##. +.###..... +#...#.... + +#.####.###......# +########.#.####.# +#..##..##...##... +##.##.##......... +#......##.######. +....#.....#....#. +#..##..#....##... +#.#..#.##..####.. +.##..##.#.######. +..####....#.##.#. +..#..#..##......# +#.####.###.####.# +.##..##..#..##..# + +.......#.#.#..##. +.##....#..##.#... +..#.#.#.##..#.##. +.####.#####.##... +#.#..#...####.#.# +..#..####.#.#.### +..#..####.#.#.### +#.#..#...####.#.# +.####.#####.##... +..#.#.#.##..#.##. +.##....#..##.#... +.......#.#.#..##. +######.....#.##.# +.###.###..##.#... +.###.####.##.#... + +######..#.. +##..#..#### +##.#.#.###. +..###..##.# +..#....##.. +...#..##... +....#....#. +....#....#. +...#..##... +..#....##.. +..###..##.# +##.#.#.##.. +##..#..#### + +....#.##.##.#.### +...#..#.#...#.... +..##..#.#...#.... +....#.##.##.#.### +########.##.##.#. +#.##.....##...#.. +.#..#....##.#.... +.#.#..##.#.#.##.# +#####.#...##...## +#.#######...##... +##..#.##.#.##.### +#..#......##..#.# +#..#......##..#.# +##..#.##.#.##.### +#.#######...##... +#####.#...##...## +.#.#..##.#.#.##.# + +..####..#.#.....# +##.#.#..#.#...#.. +#####.#.#.#.#..## +.###...##..##.#.. +##..#....##..#.#. +##..#....##..#.#. +.###...##..##.#.. +#####.#.#...#..## +##.#.#..#.#...#.. +..####..#.#.....# +..####..#.#.....# + +..####..####....# +##..#....#..####. +.##........##..## +.....####........ +#.##.####.##.##.# +##...####...####. +...#..##..#...... +####.#..#.####### +##....##....####. +.#....##....#..#. +.#.##.##.##.#..#. +.#####..#####..## +##.#.#....#.####. +##..######..####. +..##.#..#.##....# + +.##.##..##..# +#..#......... +#.##..##..##. +###..######## +######......# +..#..######## +..##.######## +..#.######### +..###.##..##. +.##..#..##..# +#####.##..##. +.#........... +.#.##.##..##. +#..##.##..##. +..########### +###..######## +##.#.#..##..# + +....##....##. +####.#.##.#.# +..####....### +...##.#..#.## +..##..####..# +..########### +.......##.... +#####.#..#.## +######....#.# + +....##.#.#.##.# +....#######..## +##.#..#..#....# +###....###....# +...#...#...##.. +..####....####. +...#.#.#.##..## +###......##..## +......#....##.. +##.###.####..## +..#..##...#.... +..#..#...#.##.# +##.#.#.....##.. +##.#.##...####. +...#..#.#...... +#####.####....# +##.###.##.#..#. + +#.#....#.##.. +##.#..#.##... +#.######.#... +.##.##.##.... +#........#.#. +##.####.###.. +....##.....## +##......###.. +..######...## + +...###.#.#.#. +#..#.##..#.#. +#.###..#.##.. +#.#..###..... +#.#..###..... +#.###..#.##.. +#..#.##..#.#. +...###.#.#.#. +##.##.#.###.. +....#.###...# +#.#####.#.#.. +#.#####.#.#.. +....#..##...# + +....####...#... +....#.....#.#.# +.....##...##... +..#..#..#.#..## +###..#..#.##### +##.##..##...... +##..#.#.#.#.#.. +....#.####..... +####.####.#.#.. +..###.###...### +#######....##.. +###.....####... +###..#....#.#.. + +..####. +###.#.. +.#..### +..#.#.. +####.## +#.#.#.. +#.#.... +.##.### +..#..## +..#..## +.##.### + +##.######.### +.##########.. +..#......#... +#.##.##.##.## +###......#### +.#.##..####.. +..########... +..#.#..#.#... +#..#.##.#..## + +.##.#...##. +#.##.#.##.. +#.##.#.##.. +.##.#...##. +#..#.#..### +.####.###.# +...#..###.. +####.#.#### +###.##...## +#...#..#### +##.##.....# +####.#..#.. +####.#..#.. +##.##.....# +#..##..#### + +###.#...####...#. +.###.#.#....#.#.# +#.###..##..##..## +###.#..........#. +###.#..........#. +#.###..##..##..## +.###.#.#....#.#.# +###.#...####...#. +.###...####.#...# +#..#.#..####..#.# +....##.#.##.#.##. +#.#..####..####.. +##.#.#.##..##.#.# +####..#..##..#..# +..####..#..#..### +#.###..#.##.#..## +##.##..##..##..## + +..##..... +###...##. +#..#.#### +..##..##. +#.#.#.##. +#.#.#.##. +..###.##. +#..#.#### +###...##. +..##..... +.##...##. + +..##.##.###..#. +..##.##.###..#. +#.##.###.#.##.# +..###...#.##.#. +.##....##..##.. +.###.######.... +...####..###.## +#####.##.###.## +###..#.###..... +###.#..#.##.#.. +..#..#....#.##. +###.#.##.##.... +##.##....##..## +##.##....###.## +###.#.##.##.... +..#..#....#.##. +###.#..#.##.#.. + +##.#..#...# +..###...#.. +....#.##### +..#.###.##. +#######..## +###...#..#. +....###..## +..#.###..## +###...#..#. + +...#.##..##.# +...#.##..##.# +#..#..#..##.# +..#.#.####.#. +..#.########. +.#.#........# +.###..####..# + +#..#.#####.##.. +........#...### +#####.##.#.#### +#####...##..... +....#.#..###### +..#.####..###.. +.##.#..##.###.. + +#...####. +#.##.##.# +#..###### +...#.##.# +...#.##.# +#..###### +#.##.##.# +#...####. +#.#.#..#. +..#.#..#. +#..#.#### +.#....... +..###..## +.#.##..## +.##.#..#. + +....####..# +##..####### +##..##.#### +....####..# +...##.##..# +.#...###### +.####.#.##. +#......#..# +.##...##### +.#..##..... +#......#..# + +#.#.#....###.#..# +#...###..#..##### +.#.#..####.##.##. +#.#......#...#### +..###.#.##..##..# +..#.#....#.###### +#..#.####..###### +.##.#..#.###..... +###....#.#....##. +.##.#.###...##### +.##.#####...##### +###....#.#....##. +.##.#..#.###..... +#..#.####..###### +..#.#....#.###### + +#..#...#### +.##.###.#.. +##.###....# +.....##..## +.....##..## +##.###....# +.##.###.#.. +#..#...#### +##..#.###.. +.......##.. +..##.####.. +..##.####.# +.......##.. + +##...#..#...### +###..####..#### +.###..##..###.. +##.########.### +#..#..##..##.## +###..#..#..#### +##.#.#..#.#.### +.#..#.##.#..#.. +.#.##....##.#.. +#..#......#..## +....#....#..... + +.##..#####. +.....##.#.. +###.###.#.. +####...#### +..#...##.## +#...####.## +.#...#.#### +##....#.... +.#.#.###### +....#..#.## +....#..#.## +.#.#.###### +##....#.... + +#.#.#.##..... +#......#####. +.###..#..#.## +.###..#..#.## +#......#####. +#.#.#.##..... +###..##..#.#. +###..##..#.#. +#.#.#.##..... +#......####.. +.###..#..#.## + +.#....... +#.####### +..##.#### +.....#..# +#..##.##. +..#...... +#..##.... +#.#.##..# +.###.#### +.###.#### +#.#.##..# +#..##.... +#.#...... +#..##.##. +.....#..# +..##.#### +#.####### + +..##.#....#.# +....###..###. +...#...##...# +..##.#.##.#.# +####...##...# +####.#....#.# +####.#....#.# +..###......## +..###....#.## +##....#..#... +##..########. +.....######.. +######.##.### + +..#.######. +..#..#####. +#...#..#.## +#.#.#..##.# +##..##..#.. +.#..###.### +.####.#.#.# +...#.####.# +.#..#####.# +.#..#####.# +...#.####.# +.####.#.#.# +.#..###.### +##..##..#.. +#.#.#..##.# +#...#..#.## +..#..#####. + +##.#.#### +.##.#.#.. +.##.#.#.. +##.#.#### +###.###.. +#.#..#.## +#...##... +##.#...## +...##.### +##..#.#.. +..##..#.. +..#...... +#.#.#.#.# + +..#.####.#. +###.####.## +....####... +..#.#..#.#. +##..#..#..# +###.####..# +##..#..#..# +..#......#. +..#.#..#.#. +....#..#... +....#..#... +##.#.##.#.# +....####... + +#...##..# +...#....# +..#.###.# +#....#... +..##.#### +.#.#####. +.###.#... +.###.#... +.#.#####. +.###.#### +#....#... +..#.###.# +...#....# +#...##..# +#.#.##.## +###.#..## +###.#..## + +###.##.#..##..# +.........#..#.. +#.#..#####..### +....#.##.####.# +....#.##.####.# +..#..#####..### +.........#..#.. +###.##.#..##..# +##..#.####..### +.#.##.##......# +.##....#.####.# +.#.###...####.. +###............ +.###...#.#..#.# +#..#..#.##..##. + +...####.##.## +.##..##....## +##...#......# +#...#..#..#.. +#####.##..##. +###..#..##..# +#..#.##.##.## +#...##.#..#.# +##.#..##..##. +.##..#.####.# +..#..#.####.# + +#.#..#.##...#.### +###..#######.#.## +.##..##..#..##..# +.#....#..#...#### +.#....#..#...#### +.##..##..#..##..# +###..#######.#.## +#.#..#.##...#.### +.#....#.#####...# +.#....#.#....#... +#..##..##...#.... +..#..#....#....## +..####..#.##.#..# +.#.##.##...#####. +##.##.###.#.#.... + +..#...### +.#.#.#### +.#.#.#### +.##...### +..#....## +..###.... +##....### +#..###... +..#.##### + +..####### +###.##..# +###...#.. +######..# +..####..# +..#.#.... +...###..# +##..##..# +..##.#..# +..#.#.... +###...... +##.###### +....#.##. + +###.##.#####..##. +.#.####.#.#...##. +.##....##.#..#..# +.###..###.#.#.... +.########..#..##. +####..####..##### +..#.##.#......##. +###.##.####..#### +##########...#### +#.#....#.##..#### +.#..#...#.#..#### + +....#.##.#... +####......### +##.#..##..#.# +####.####.### +####.####.### +##..........# +..#.#.##.#.#. +...######.#.. +##.##....##.# + +..#.....# +..#.....# +....##.#. +##.#####. +..#..#... +..#...##. +#.#.....# + +###..##..####..#. +##..#..#..##..... +.##.#..#.##..#### +..##....##..##### +#.#..##..#.###### +#.#......#.###..# +##..#..#..####### +..##.##.##..#.##. +####.##.#####.... + +..##..###.# +..#..#...#. +..###.##..# +..#.#.####. +.#..##..#.. +...#.#.##.# +####......# +####......# +...#.#.##.# +.#..##..#.# +..#.#.####. +..###.##..# +..#..#...#. +..##..###.# +#....#..#.# +#....#..#.# +..##..###.# + +#...####### +#.#.####### +#....#.#### +#....#.#### +#.#.####### +#...####### +#.##.##.### +#...#...##. +##.##..##.# +###.####.## +....##.#... + +#..#### +..###.# +###...# +.#.###. +.##..#. +.##.#.. +.####.. +.##..#. +.#.###. +###...# +..###.# +#..#### +##...#. +##...#. +#..#### + +....##.##.#####.# +#...##.##....##.# +.###.#####..##### +...####...##...## +#.#.#.###....###. +#######...##...## +.########.##.#### +..#.######..##### +#..#..#.######.#. +##..#.##..##..##. +.#..#.##..##..##. +.#.#.###..##..### +....#...##..##... +######.#......#.# +##.#######..##### +##.#######..##### +######.#......#.# + +#######......## +...##.########. +#.##........... +#######......## +.#.#..##.##.##. +#.............# +#.#.....####... +##.###........# +##.##.#......#. +...###..#..#..# +.#.##.......... +.####..#.##.#.. +.####..#.##.#.. + +.#..#..####.####. +.#####...###.##.# +#.##.#...##...... +.####.##...##..## +..##..#.#.#.#..#. +.####.#.#...#..#. +##..##.#..#.####. +.#..#.#.....#..#. +......#....#....# + +###...# +###.#.# +#.##### +###...# +...##.# +....##. +####.#. +####.#. +....##. +...##.# +###...# +#.##### +###.#.# + +#..##....##..#.#. +#..##....##..#.#. +#.....##.....#.#. +..###.##.###..### +...##....##....#. +.#..#.##.#..#.### +....#....#....#.# +.#....##....#..#. +####.####.#####.# +###.######.###... +..#..#####.#....# +#..#.#..#.#..##.# +..#..#..#..#..##. + +##.#..# +##.#..# +#..#### +...#... +#.##### +..#..#. +..##.#. +#.##### +...#... +#..#### +##.#..# + +..##........# +##..###..##.. +#.##.##..##.# +......####... +.......##.... +.####......## +.#..#.#..#.#. + +.#..#..#.##.# +..##.....#..# +.......#...#. +#.##.###.#### +#.##.###.#### +.......#...#. +..##.....#..# +.#..#..#.##.# +########..### +.#..#.##.#### +.####..##..## +.##.#..##.##. +.####.###.##. + +#...##...###.#.## +##..####.#.#.##.# +....#..#.....##.. +.#..##..#.#.##### +###........##..## +###........##...# +.#..##..#.#.##### +....#..#.....##.. +##..####.#.#.##.# +#...##...###.#.## +...##.#.#.......# +##...#..###.###.. +##...#..###.###.. +...##.#.#.......# +#...##...###.#.## + +##.#..##.##.# +#####........ +#####........ +##.#..##.##.# +..#.#..###### +...#.....#... +...#..#..##.# +......##..#.# +..##.###.##.# +#...##.#.##.. +.....####...# +#####..##.### +..#.####.###. + +###.###.# +##.#.##.. +..####... +...#..#.# +....##.#. +###....#. +###.###.. +...#...## +..##.###. +..##.###. +...#...## +###.###.. +###..#.#. +....##.#. +...#..#.# + +..##..# +..##..# +..#...# +.....#. +##..##. +##.#.## +..#...# +#....#. +##..... + +.#......#....#... +#........#..#...# +#..####..#..#..## +..........##..... +..#.##.#..##..#.# +.#..##..#....#..# +#..#..#..####..#. +##..##..##..##..# +..#.##.#..##..#.# +.#..##..#....#..# +#..#..#..####..#. +####..##########. +.#.#..#.#....#.#. + +####.## +..##... +.#..#.. +.####.. +.#..... +..###.. +..###.. +.#..... +.####.. +.#..#.. +..##... +#.##.## +.#..### +#...#.. +...#.## + +.#.#..#.#.##### +.###..###.#.... +#..#..#..###### +..######....... +.#.####.#..#### +##..##..####### +#...##...###..# +##......##.#### +###.##.#####..# +.##....##.##### +.#.####.#.##... +#.######.###### +##..##..###.... +..##..##..#.... +..#....#...#..# + +#.##..##.#. +##########. +###.##.###. +##.#..#.### +...#..#...# +...####...# +....##....# + +.....#..##. +..###.#..## +##.#...#.#. +##.....#.#. +..###.#..## +.....#..##. +.......#.## +.###.#..... +.###.#..... + +...#.#..##..# +###.....##... +....#.#....#. +#.#....#..#.. +#.#....#..#.. +....#.#....#. +###.#...##... + +##..#.####.#..##. +##..#.####.#..##. +####.#.##.#.####. +#.##........##.#. +.##..######..##.# +####..####..#.##. +..#..........#... +##..###..###..##. +.#..#..##..#..#.. +##.##..##..##.### +.####......####.. + +..##..#.###....## +##..##..#..#..#.. +#....######....## +#....#..#........ +......##.#..##..# +#....#.###..##..# +#....#.##..#..#.. +##..#######.....# +.####..####....## +.#..#..##.######. +#.##.#.##.######. + +##.#.#.###..# +...######.#.. +..###.#.#.... +#.#.###.##.## +#######.#.#.. +###...##.#... +.#.#.###..... +###..#.##.### +#####..###### +.....#.#..### +.####..#..#.. +#.###.##..### +.##.....#..## +.#.#.####.... +.#.#.####.... +.##.....#..## +#.###.##..### + +#.#..###.####.### +#.#..###.####.### +#...###........## +.....#.########.# +.#####.#......#.# +#..#...###..###.. +.##.##..#....#..# +#.#....#.####.#.. +##...#.########.# +.#.##.#.#.##.#... +..##..###.##.###. + +.#..##.## +....##.## +....##.## +.#..##.## +...#..#.. +.#.####.# +##.#..##. +#...###.# +.####...# +....##### +#.#.#.#.# + +..#..#....... +.#.##...##### +...######..#. +...######..#. +.#.##...##### +..#..#....... +#......#.###. +##..#........ +#...##..###.# +##.##.#.#..#. +##.##.#.#..#. +#...##..###.# +##.##........ + +..####...####.# +...##.##..##... +...##.##..##... +..####...####.# +###...#...##### +.#.#.##.#.#.##. +#####..###.##.. +...#.#..#..#### +####..#.......# +.#.#.##.#.#..#. +..####.#....... +....#.##.#.#.#. +##..#..#..####. +##..#..#..####. +....#.##.#.#... + +#..##.##.## +.#......... +#.##..##..# +#..###..### +###.##..##. +#####.##.## +##..#.##.#. +##..#....#. +.#..#....#. + +##.#..#.### +.########.. +.########.. +##.#..#.##. +..#.##.#... +##......##. +##########. +##..##..##. +.##....##.# + +...##...#.##### +.######...##### +#......##...#.# +..#..#..####### +#..###.#.....## +...##.......... +...##...####..# +########....##. +##.##.##..##..# +.##..##.##....# +#.#..#.##.#..#. +.#.##.#...####. +.#.##.#...####. + +..#..##..#..#...# +#.#..##.#....#.## +##.#...###..###.. +##...#..##..##..# +#.###.##.####.##. +###...##..##..##. +######..######..# +######..######..# +###...##..##..##. +#.###.##.####.##. +##...#..##..##..# + +#.#.##...#. +#..#.##..#. +#..#...#... +#..#...#... +#..#.##..#. +#.#.##...#. +##..#.##.## +#.##.###.## +###..##...# +#.#.##..##. +#..#.#.#### +#..#.#.#### +..#.##..##. + +..#.#.#.#..#.#. +##.#.#...##...# +...#...#....#.. +..#............ +###.#..##..##.. +......#..##..#. +####.#..#..#..# +###.#..######.. +...#...##..##.. +..##.########## +##....##....##. +###..#.#....#.# +###.#..#.##.#.. +..##..##....##. +...#..#.####.#. +#.#####......## +..#..#...##...# + +#..####.... +####.###### +.......#... +....#...#.. +####....... +#..#.....## +#..#...#### +#######.... +....###.#.# +.........## +.....#.##.. +######..### +#..##..##.. +#..###.#... +#..#.#..... +#..###.##.. +#..#..#.#.. + +#...##.#.## +#...##.#.## +.###..#.#.# +##.###..#.. +..#...##..# +....##.#### +##.###.#.#. +##.###...#. +....##.#### +..#...##..# +##.###..#.. +.###..#.#.# +#...##.#.## + diff --git a/src/day13/part1.pas b/src/day13/part1.pas new file mode 100644 index 0000000..877129b --- /dev/null +++ b/src/day13/part1.pas @@ -0,0 +1,142 @@ +{$mode objfpc} +{$RANGECHECKS ON} + +program day12part1; +uses sysutils; + +type + Tmap = record + map: array[1..100] of string; + height: int32; + width: int32; + end; + +function max(a, b: int32): int32; +begin + max := a; + if b > a then + max := b; +end; + +{ check for mirrors that lay vertically (column mirror) } +function check_v_mirror(map: Tmap; col: int32): boolean; +var + i, j: int32; +begin + + check_v_mirror := true; + for j := 1 to map.height do + begin + for i := max(1, 2 * col - map.width + 1) to col do + begin + // writeln(i, ' ', col*2 - i); + if map.map[j, i] <> map.map[j, col * 2 - i + 1] then + begin + check_v_mirror := false; + break + end; + end; + + if not check_v_mirror then + break; + end; + + check_v_mirror := check_v_mirror; + +end; + +{ check for mirrors that lay vertically (column mirror) } +function check_h_mirror(map: Tmap; row: int32): boolean; +var + i, j: int32; +begin + + check_h_mirror := true; + for j := 1 to map.width do + begin + for i := max(1, 2 * row - map.height + 1) to row do + begin + //writeln(i, ' ', row*2 - i + 1); + if map.map[i, j] <> map.map[row * 2 - i + 1, j] then + begin + check_h_mirror := false; + break + end; + end; + + if not check_h_mirror then + break; + end; +end; + + +function get_mirror(map: Tmap): int32; +var + i: int32; +begin + { check vertical ones first } + for i := 1 to map.width - 1 do + begin + if check_v_mirror(map, i) then + begin + get_mirror := i; + exit; + end; + end; + + { check horizontal ones now } + for i := 1 to map.height - 1 do + begin + if check_h_mirror(map, i) then + begin + get_mirror := i shl 6 + i shl 5 + i shl 2; + exit; + end; + end; + +end; + +var + + map: Tmap; + file_: text; + s: string; + total, map_count: int32; + +begin + + assign(file_, 'resources/day13.txt'); + reset(file_); + + total := 0; + map_count := 0; + + while not EOF(file_) do + begin + + readln(file_, s); + writeln(s); + if length(s) = 0 then + begin + // come back to this + + total := total + get_mirror(map); + + map_count := 0; + + end + else + begin + + map_count := map_count + 1; + map.map[map_count] := s; + map.height := map_count; + map.width := length(s); + + end; + + end; + + writeln(total); + +end. \ No newline at end of file diff --git a/src/day13/part2.pas b/src/day13/part2.pas new file mode 100644 index 0000000..7d076ca --- /dev/null +++ b/src/day13/part2.pas @@ -0,0 +1,149 @@ +{$mode objfpc} +{$RANGECHECKS ON} + +program day12part1; +uses sysutils; + +type + Tmap = record + map: array[1..100] of string; + height: int32; + width: int32; + end; + +function max(a, b: int32): int32; +begin + max := a; + if b > a then + max := b; +end; + +{ check for mirrors that lay vertically (column mirror) } +function check_v_mirror(map: Tmap; col: int32): boolean; +var + i, j: int32; + errors: int32; +begin + + errors := 0; + for j := 1 to map.height do + begin + for i := max(1, 2 * col - map.width + 1) to col do + begin + // writeln(i, ' ', col*2 - i); + if map.map[j, i] <> map.map[j, col * 2 - i + 1] then + begin + errors := errors + 1; + if errors > 1 then + break; + end; + end; + + if errors > 1 then + break; + end; + + check_v_mirror := errors = 1; + +end; + +{ check for mirrors that lay vertically (column mirror) } +function check_h_mirror(map: Tmap; row: int32): boolean; +var + i, j: int32; + errors: int32; +begin + + errors := 0; + for j := 1 to map.width do + begin + for i := max(1, 2 * row - map.height + 1) to row do + begin + //writeln(i, ' ', row*2 - i + 1); + if map.map[i, j] <> map.map[row * 2 - i + 1, j] then + begin + errors := errors + 1; + if errors > 1 then + break; + end; + end; + + if errors > 1 then + break; + end; + + check_h_mirror := errors = 1; +end; + + +function get_mirror(map: Tmap): int32; +var + i: int32; +begin + { check vertical ones first } + for i := 1 to map.width - 1 do + begin + if check_v_mirror(map, i) then + begin + get_mirror := i; + exit; + end; + end; + + { check horizontal ones now } + for i := 1 to map.height - 1 do + begin + if check_h_mirror(map, i) then + begin + get_mirror := i shl 6 + i shl 5 + i shl 2; + exit; + end; + end; + + if get_mirror = 0 then + writeln('oh fuck'); + +end; + +var + + map: Tmap; + file_: text; + s: string; + total, map_count: int32; + +begin + + assign(file_, 'resources/day13.txt'); + reset(file_); + + total := 0; + map_count := 0; + + while not EOF(file_) do + begin + + readln(file_, s); + if length(s) = 0 then + begin + + total := total + get_mirror(map); + + map_count := 0; + + end + else + begin + + map_count := map_count + 1; + map.map[map_count] := s; + map.height := map_count; + map.width := length(s); + + end; + + end; + + writeln(total); + +end. \ No newline at end of file