advent-of-code-2023

My solutions to AoC 2023
git clone git://git.entf.net/advent-of-code-2023
Log | Files | Refs

commit be76554e85d7a77b4e6a473b9761762daa0ee338
parent b422a1c50fd4de5f2f29dee2e1ad6d62fc2d4915
Author: Lukas Henkel <lh@entf.net>
Date:   Wed, 13 Dec 2023 06:42:18 +0100

Day 13 task 1

Diffstat:
Ainput/13.txt | 1311+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/day-13.lisp | 38++++++++++++++++++++++++++++++++++++++
Msrc/utils.lisp | 14++++++++++----
At/day-13.lisp | 23+++++++++++++++++++++++
4 files changed, 1382 insertions(+), 4 deletions(-)

diff --git a/input/13.txt b/input/13.txt @@ -0,0 +1,1311 @@ +.##.###..####.. +....#..#.####.# +.##.###...##... +.##..###..##..# +.##..##..#..#.. +####.#####..### +####.##..####.. +#..###..#.##.#. +#..#....##..##. +...#.#.###..### +......#.#.##.#. +.....##...##... +#####...##..##. + +....#.#..#. +####.##.### +##.##..#### +..#.#.#.... +#...#.###.# +..#.###.### +..#.###.### +....#.###.# +..#.#.#.... +.#.#....##. +.#.#....##. +..#.#.#.... +....#.###.# +..#.###.### +..#.###.### +#...#.###.# +..#.#.#.... + +......########... +....#..#.##.#..#. +##....########... +###..#.#.##.#.#.. +...#....####....# +#####.########.## +..#....##..##.... +###....#.##.#.... +##.#.#..#..#..#.# +###.....####..... +###.#.##....##.#. +###.#####..#####. +...#...#.##.#...# +..#####......#### +..#.####.##.####. +......#.#.##.#... +..#.####.##.####. + +##.#.##.#.# +.###.##.### +.###.##.### +##.#.##.#.# +.########## +.########## +...##..##.. +..#.####.#. +###..##..## +###..##..## +##.##..##.# +##..#.....# +..#.####.#. +..#.#..#.#. +#..#.##.#.. +#.#.####.#. +##..#..#..# + +#.#..#.#. +#...##### +.#..##..# +##..#.#.# +..##.###. +..##.###. +##..#.#.# +.#..##..# +##..##### +#.#..#.#. +.###.#.#. +###.#...# +..#.#.#.. +...##.#.. +...##.#.. + +.######## +####.##.# +#.##..#.# +....#..#. +.#.##..## +#.###..## +...##..## +####.##.# +#....##.. +###...... +.#..####. +.####..## +.####..## +.#..####. +###...... +#....##.. +####.##.# + +..##..##..#.# +..##..##..#.# +##...####...# +#.......#..## +.#..##.#.#.#. +#.##.......#. +..#.#...##... +#.#..#.##..#. +#.#..#.##..#. +..#.#...##... +#.##.......#. +.#..##.#.#.#. +#.......#..## +##...####..## +..##..##..#.# + +##########. +###.##.#### +..######... +.##....##.. +##......### +###....#### +..#.##.#..# + +####.####.####### +...##.##.##...... +.############.#.. +###.##..##.###... +.#.#..##..#.#.#.. +##...####...###.. +#....#..#....##.. +....#....#....### +.#..#.##.#..#..## +...###..#.#...#.. +#..#......#..#.## + +..##...#.## +..##...#.## +....#.##..# +#...###.### +...##.##.#. +.####....#. +.#.#...#.#. +.#.###.#.#. +.#.###.#.#. +.#.#...#.#. +.####....#. +...##.##.#. +#...###.### +....#.##..# +..#....#.## + +...#####..# +.#...##...# +.##...#...# +##.#......# +..#..##.##. +..##.##.##. +##.#......# +##.#......# +..##.##.##. +..#..##.##. +##.#......# + +###..#.#. +##...#.#. +......#.. +##..#.### +##.###.## +..####.#. +....#.##. +....##.#. +#....#... +##..##.## +##..##.## +#....#... +....##.#. +....#.##. +..####.#. + +.####..#..#.. +.####........ +#.##.#..##..# +#######..#.## +##..##......# +######.####.# +.####..####.. + +#..###..##..### +#..##..####..## +.....###..####. +######..##..### +....#........#. +#####.#....#.## +#..#.#.####.#.# + +#..###...#.#..#.# +#..###...#.#..#.# +##...##.#.#.##### +#.####........#.. +##..#..#..#...#.. +.###.##..#####.## +....#..###..#.#.# +..###...#........ +..###.#.#........ +....#..###..#.#.# +.###.##..#####.## +##..#..#..#...#.. +#.####........#.. + +#..#..# +..###.# +..####. +###.#.# +.###..# +.###### +###.... +###.... +.###.## +.###..# +###.#.# +..####. +..###.# +#..#..# +#..#.#. +#...##. +#...##. + +.....###..... +##..#..#..### +.###.##.###.. +#..######..## +.##.#..#.##.. +.##......##.. +.###....###.. +##..#..#..### +.##.#..#.##.. + +.....###..#.. +#.#...#.#..## +#####.##.#### +#..#..##.#### +#...#####.### +##.###.###.## +.#.###....#.. +.#.###....... +##.###.###.## + +...#.#....# +..######### +###.####### +##..###..#. +..#.####### +##....####. +..#..#....# +###..##..## +....####### +##.###....# +#######..## +...###....# +##..####### +###..#.##.# +##....#..#. + +..##..####..###.. +######...##..##.# +######...##..#..# +..##..####..###.. +######.##...####. +..##...###..#.... +#.##.##.####..... +........#######.. +.#..#.#...#...#.. +#....##..##...### +##..##..###.##.#. +#....###.####.... +.#..#.#.###.#...# + +#....##..#... +.##.......#.. +##.##..##..## +.#.##..##..## +.##.......#.. +#....##..#... +#...###.###.. + +.#....#.. +##.##.### +##.##.### +.#....#.. +.######.# +##.##.### +........# +##.#..##. +.######.# + +.......##.####.## +......#.##.##.##. +.#..#.#.#.....##. +##..#####..#.#..# +#.##.#.#.##.#.... +..##...###.#.#..# +......#..#....... +.####....##...... +.......##.##.#### +.#..#.##.###..##. +########..###.##. + +.....####.... +#####....#### +##..##..##..# +#.##......##. +#.##########. +..##..##..##. +#.##..##..##. +.####.##.#### +##..#.##.#..# + +#...#.####. +..##.###..# +#.#.##..... +########..# +..#..###..# +#....##.... +##..#..#..# +#..####.... +#..####.... +##..#..#..# +#....##.... +..#..###..# +########..# + +##..#......#.#..# +#...#......#.#..# +..#.#.#.##..#.... +###.###.##...#### +#..##.#...#.#.##. +#.####..##.#.#### +...#.#...#.##.##. +#.####.###..##..# +##..#..##.....##. +####.....##.##..# +.#.....##.###.... + +###..#######. +.##..##.###.# +##.##.##.#.#. +##.##.##.#.#. +.##..##.###.# +###..#######. +#......#..#.# +..####.##...# +#.####.####.. +.#.##.#.##... +#.#..#.#...## +#......#####. +##########.#. + +.#..#.##..# +######.#..# +......###.# +#....###..# +.#..#.#.#.. +.........#. +###.######. +#....#.#.## +......#.### +######.#... +#....#.##.. +#....#.##.. +######.#... +......#.### +#....#.#.## + +....##......##. +..#..##.##.##.. +###..#.####.#.. +...##.#....#.## +.#...#.####.#.. +#####...##...## +..#...#....#... +#######.##.#### +##.#####..##### +....#...##...#. +###.#.#.##.#.#. +..#.##########. +...#..........# +..#...######... +####...#..#...# + +#.#.##..#.. +#.....#.### +#####.##.## +#.####..... +##..###.... +#...#...#.. +##...###.#. +.#.######.. +.#.######.. + +##.#.#..# +..#.##.## +#....#### +##.##.#.. +.##...### +.##...##. +##.##.#.. +#....#### +..#.##.## +##.#.#..# +.#..##.## +.#..##.## +##.#.#..# +..#.##.## +#....#### + +.##.###........#. +##.#.##...#.##### +.#..#.###.#####.# +.#..#.###.#####.# +##.#.##..##.##### +.##.###........#. +##.##..#....#.### +#...#....######## +.###.#..###.....# +.###.#..###.....# +#...#....######## +##.##..#....#.### +.##.###........#. + +#.#....#.##.### +...#..#...#.### +..........##### +##########..... +#.#.##.#.#..#.. +......#...#.### +.#......#...... +#..####..#.#... +....##....##.## +#.######.#..### +##.#..#.###..## +##......##.##.. +.##....##.##.## + +#.###.### +#.###.### +.##.##### +###.##..# +..##.#.## +.###.#.## +..#.#.#.# +.#.#...#. +#..###.#. +#..###.#. +.#.#...#. +..#.#.#.# +.###.#.## +..##.#.## +###.##..# +.##.##### +#####.### + +......#.#..###. +###..####....#. +####..###.###.. +###.######..... +#######.#.##... +#######.#.##... +###.######..... +####..###.###.. +###..####....#. +......#.#..###. +#####...#####.# +.#.###.#..#.### +###..###...#... +..##....##..... +###.##..##.#.#. +####...##.#.#.# +####..#.#.###.. + +...##...... +..#....##.. +###..###### +#.#.##....# +..###.#..#. +....#.####. +######.##.# + +#..##....###. +#..##....###. +#....#.###... +.####.##.#.## +.####..#...## +####.#...#... +.###...#.#... +.###...#.#.#. +####.#...#... +.####..#...## +.####.##.#.## + +..##..#.##...#.## +....##....#..#... +....##....#..#... +.###..#.##...#.## +####.....#.....## +#.##...##.##.##.. +.###.....####.### +#.#...###.##.##.. +#.....###.#####.. +##.##.#..#.#...## +.#####.##..#...## +.####.#.#....#### +.#.#.##.#.####... +..#..##...#.##### +.####...##..##... + +##..#.# +##..#.# +...###. +##.#.## +.#..### +..#..## +......# + +..##.## +##..### +.###..# +####.## +#.##.## +#.#...# +#.##### +###.... +#...... +.#.###. +.#.###. +#...... +###.... +#.##### +#.#...# +#.##.## +####.## + +#.####.#..###.##. +.#....#.#.#.##..# +##....##.##.##..# +.#....#.#.##..##. +###########..#..# +.#....#..#..##### +..#..#....###.##. +.#.##.#..#...#..# +#..##..##.##.#### +##....#####.##### +.###.##....##.... + +.####...##....# +#.##.##.##....# +########..####. +######.#..####. +.####...#...... +..##..#........ +#########...... +.####..###....# +#....#####...## +#....#.#.##..## +..##....#.####. +..##...######## +######...##..## +.####.#.#.#..#. +.#..#...#...... + +.#..#.#..## +.#..#.#..## +..####..... +##.....##.. +..#.#....#. +..####.###. +....#.##..# +##.#..###.# +##.#..###.# +....#.##..# +..####.###. +..#.#....## +##.....##.. +..####..... +.#..#.#..## + +#######..#...## +....#.#.#.###.# +##.....##...... +##.....##...... +....#.#.#.###.# +#######..#...## +#.##.#.###.###. +##..#.##.....#. +.#.##...####... +###.###..##..## +..##.....#..... +..##.....#..... +###.###..#...## + +.#.###.###### +.....#..#.#.. +#..#.##...... +..##.####.### +#.#...##...## +..#.###..#### +##.#.#..##... +.##.#.##.#.## +..###.#.#.#.. +.#.#.#.###.## +##.###..##... +##.###..##... +.#...#.###.## + +###..#####.##.### +..###.#####..#### +###....#.##..##.# +##.####..######.. +..#.#..##.#..#.## +##..###..#....#.. +###.##...######.. +....#..###....### +##..##.####..#### +##.#.#...#.##.#.. +..#.#####..##..## +#####.....#..#... +#######.##.##.##. +.....#.##.#..#.## +###..#.#.######## +..#..######..#### +##.##.....####... + +..#........ +#..#..##..# +####..##..# +..###....## +..###....## +####..##..# +...#..##..# +..#........ +#.##..##..# +...#.####.# +.#.#.#..#.# + +###.#.####. +.##.####### +.####.####. +###.#...... +##...#.##.# +.#.###....# +.####.#.... +#....##..## +.##....##.. +##.###....# +.#.#..#..#. +.##.#.#..#. +#.#..#.##.# +#.#####..## +.#.#.###### +#..####..## +#..####..## + +####.##.#.### +##.##.#.##### +###..#.#.#..# +##..#..#.#### +...#.##.##### +...#...#..... +..#.##.#..... +..###.#.##..# +##.#######..# + +.#.#.###### +.#....##..# +.##..#.#..# +.#####..##. +###.#..#### +...##.#.... +.#..##..... +.#..##..... +...##.#.... +###.#..#### +.######.##. +.##..#.#..# +.#....##..# + +####..##..# +.##........ +.##..####.. +####.....## +#####.##.## +.....#..#.. +....#....#. + +..#..#. +....#.# +##.##.# +##...## +...#... +##..##. +##.###. + +.####..#.#.##...# +.####.##.#..#...# +.####.#.....##..# +..##...#####...#. +#.##.#.###..##... +.####.#.#.##.###. +##..###..#...#... +.####.#....##.### +.####.#...###.### + +...#..##### +.....#..#.# +#.###..#.## +#.###..#.## +.....#..#.# +...#..##### +#.#...#.##. +#.#.#.##.## +#..#.##.... +.##...##..# +..#...##..# + +..####.##.# +...###.##.# +.#..##.##.# +.###.##..## +...#.#....# +#.#...####. +...#....... +.#.##.#..#. +#....#.##.# +#....###### +...#....... + +#..##...####...## +..#...###...##... +.#.#.##..##..##.# +..#...#..##..#... +..#.#.##.##.##.#. +.###.##.####.##.# +......#..##..#... +##.#.#..####..#.# +##.#.#..####..#.# + +##..###..#..#.# +.####.#.#.#..## +..##..###.#.### +#.##.#.....###. +#.##.#.....###. +..##..###.#.### +.####.#.###..## + +...#.######.##.## +...#.######.##.## +#..##.....####.#. +..#######..####.. +#....####.#.##.#. +..##..#.####..### +##...#.#.##.##.## +.#.#..#.....##... +##..##.##..#..#.. +###.#..##.#.##.#. +####..#.##......# +.######..######## +###.#.###.##..##. + +..##.###..#.#.. +#..#......###.. +.#.########.... +.#.########.... +#..#......###.. +..#..###..#.#.. +.#.##.#.#.#.... +.##.###..##..## +.#...##.###..## +.##.#.###.#.... +.####..#.#..### +#..#######..### +..##..#......## + +#.#..###....### +.........#.#.## +.#....###....## +#....###..#.... +#....###..#.... +.#....###....## +.........#.#.## +#.#..###....### +..#.#..#.##.... +#.#..##..#..#.# +...#...#......# +#.#..#.#####.## +#.#..#.######## + +.#.#.#...#. +.#.#.#...## +.#.#.#...## +.#.#.#...#. +#.#..###.## +####.#....# +##.##.#..## +#...#####.# +#..##...#.# +#.###...#.# +.#.#....### +###..#..#.# +#.......#.. +.##.#####.# +##.##....#. + +######..########. +....##..###..###. +#..#..####.##.### +.....#.#.#.##.#.# +#..##...##....##. +..........####... +#..##.###..##..## +.......#..####..# +.....#....####... +#..###.#..####..# +####..#####..###. +#####..###....### +#..#.##.########. + +.#..#......#. +#####.#..#.## +#####.#..#.## +.#..#......#. +###.##....##. +###..#....#.. +#.#..######.. +..###.####.## +#...########. +###.#......#. +#.########### +##.#.######.# +.#..##....##. +..#.##.#####. +##.#.#....#.# +##.##..##..## +###.###..###. + +##.####...... +..#...#.#.##. +##.#..##.#.## +##..####..##. +.....###..... +##..##.#..##. +..##....#.... +##.##...##### +..###.#.#.##. + +####.#### +..##.#### +##..#.##. +#####.... +#..#.#### +#..#.#### +#####.... +##..#.##. +.###.#### + +#.##.#.###.## +#.##.#.###.## +##..##..##### +.####.##.##.# +.###...###..# +.#..#..#..### +..##...##.### +#....#..###.# +.#..#.......# +..##..##..### +#....##.###.# +#....#.#..... +.####.##.###. +.####..####.# +..##..#.##... + +....##########... +.##.##......##.## +...####.##.####.. +####.########.### +#.#####.##.#####. +#..##.######.##.. +###.#..#..#..#.## + +.##.##.##.#.#...# +....##.....###..# +#.##..##.#.##..## +...#..#...#.###.. +#...##...###..... +#...##...####.... +...#..#...#.###.. + +.###.#. +####.## +####.## +.###.#. +.....## +###.### +.#..### +#.#...# +.##..## +..##.#. +..#.#.# +..#...# +..##.#. +.##..## +#.#...# + +########..##. +###.#....#... +...#.###.##.# +...#.###.##.# +###.#...##... +########..##. +.....#..#..#. +....#.#..#### +##....####.## +###...#...##. +##.####.#.#.# +##.###.##.##. +....#.###.##. +......###.#.# +..######..#.. +...#..####..# +######.#.##.. + +.####.#...##.#. +..##....#####.. +#.##.##..#####. +##..###.#.###.# +.####.#.#...... +#.##.###..#...# +#.##.###..#...# +.####.#.#...... +##..###.#.###.# +#.##.##..###### +..##....#####.. + +##..##.#.......#. +..#.##...#.#...## +#..###..##.#.#..# +.#.#...####.##..# +##.#..#..##....#. +...#.#######..### +.#.##......##..#. +.#.##......##..## +...#.#######..### +...#.#######..### +.#.##......##..## +.#.##......##..#. +...#.#######..### + +.......#.##.# +##..##.###..# +.........#..# +#.##.#..####. +#######...... +#.##.####...# +#.##.#####..# + +.####.##.## +.##..#####. +....#.##... +....#.##... +.##..#####. +.####.##.## +###.#####.. +...#.#..#.. +.#....###.. +.##...#.### +##......### +##......### +.##...#..## + +###.#.#.# +#.##.##.# +#.##.##.# +###.#...# +....#.#.# +..##..#.. +.#####.#. +#.#.#...# +...###### +..#..###. +##...##.. +#.###.### +.##.###.# +###...##. +###...##. + +#.####### +#..###### +#..#....# +.#.##..## +..###..## +...#....# +##.#####. +####....# +####....# +##.#####. +...#....# +..###..## +.#.##..## +#..#....# +#..###### +#.####### +.#....... + +.###.##...####### +###..#.#####.#..# +.####.#.##.##.#.# +.##.....##.##.#.# +...######.##.#.## +...######.##.#.## +.##.....##.##.#.# +.####.#.##.##.#.# +###..#.#####.#..# +.###.##...##.#### +##.###...##..##.. +##.###...##..##.. +.###.##...##.#### +###..#.#####.#..# +.####.#.##.##.#.# + +..####..# +...#..### +#..####.. +#.#.#.##. +#####..## +..##.#.#. +..##.#.#. +#####..## +#.#.#.##. +#..####.. +...#..### +..####..# +####.#### +.###.#### +..####..# +...#..### +#..####.. + +.##..#. +#..#..# +....### +#..#.#. +#..#.#. +....### +#..#..# +.##..#. +#...#.. +####..# +.##..#. +.....#. +#..##.# + +#.##..##. +#...##... +...####.. +.######## +#..#..#.. +#..#..#.. +#...##... +.##.##.## +.###..### +#...##... +.###..### + +##.##........##.# +########..####### +...##.######.##.. +..#.#.##..##.#.#. +....###.##.###... +##.#..######..#.# +##...#.####.....# +..###........###. +#####...##...#### +..#####....#####. +....####..####... +..#..#.#..#.#..#. +#####...##...#### + +...#.######.#.. +..##........##. +##.##########.# +###.##.##.##.## +##.#..####..#.# +..#####..#####. +####.######.### +##.#..#..#..#.# +####..#..#..### +..##...###..##. +##...#.##.#...# + +..##....##. +##.##..##.# +..########. +..#.##.#.#. +..##....##. +..#.####.#. +##.######.# + +#..#..##....### +....#.#..##..#. +....##.#######. +....##.#######. +....#.#..##..#. +#..#..##....### +#..##...##.##.# +#####.#...#.... +.......#...#.## +.......######.. +.##.##.#.###... +.##.##.###.#.## +..#...###..#... + +...#..#.###.#.. +##.#####....### +.....##..##.##. +###.##..##..... +###.#.##..#.### +###..##.#..##.# +...#.##.##..##. +.....#...#.###. +..#...####.###. +..##.###...#### +..###...####### +###.#.##.#..#.. +........#..##.. +....#..#.##...# +....#....##...# + +#.##.#..#.# +#.##.#..#.# +###..####.. +.##.#..#.#. +...##.##.## +###.##..##. +#....####.. + +##.#.#.##.#.. +...##....#### +.##..##.##### +#.##.##...### +#....##..##.# +..##..#.##..# +..##..#.##..# +#....##..##.# +#.##.##...### +.##..##.##### +...##....#### +##.#...##.#.. +##.#...##.#.. + +........#..#... +#######.#.##### +.####.#.####... +.####.#...###.. +#.##.#....#..#. +.#..#......##.. +.......##..###. +##..##....##### +######.#..##### +######.#..##### +##..##...###### + +#..#....##... +..##.##.##.## +###..##.##.## +##...##.##.## +###.....##... +.....##.##.## +..###.#....#. +#......####.. +#.##......... +..######..### +##..####..### +..#.#........ +#.##...#..#.. + +##.#.#... +#.#...... +#....#### +#....###. +#.#...... +##.#.#... +..#.#.#.# +..#.#.#.# +##.#.#... +#.#...... +#....###. + +.##..##..###.## +.###.##..###.## +###.#....#..#.. +..#....#.##..#. +##...#..#....#. +..####.##.#.#.. +..####.##.#.#.. + +.##...### +#..#.#..# +...#.#..# +##.##.... +######..# +######..# +##.##.... + +########...####.. +...##....######## +...##....#......# +###...##.##....## +..####..#.#....#. +#.####.#.##....## +###..###.#.#..#.# +###..###.######## +.######..###..### + +###.#.. +.#...## +####... +##.#.## +####.## +####.## +..###.. +..#..## +###.### +..#.... +###.... +##.#.## +##..#.. +..##### +###..## + +#..#..##### +#..#..##### +#####.##.#. +###.....#.# +###.###...# +..#.#..##.# +..#.#..##.# +###.###...# +###....##.# + +#..#.#.#.#.## +####.#..##### +...#....#.#.# +#..##.###.... +.....###..##. +####..#....## +#..##..#.#..# +#..##..#.#..# +####..#....## + +.#.#...#.#..#.# +##.####...##... +#.###.#........ +.#.##...######. +.#.##...######. +#.##..#........ +##.####...##... +.#.#...#.#..#.# +.#..##..######. + +####..### +.###.#### +...###.## +.......## +..#.#.### +###.##.## +#..#.##.. +###..#### +###..#### +...#.##.. +###.##.## +..#.#.### +.......## + +####.##..#### +######.####.. +#####.###.### +#..#..#.#..#. +#..#..#.#..#. +#####.###.### +######.####.. +####.##..#### +....#......## +.##..#..#.#.. +.##.##..#.... +##.#..#.##... +#..##.##...#. +......#..###. +.....#..##.## + +#.##..###.... +....######### +##.###....... +...##..##.... +...#.#.##.... +.#.##..#..... +...#####.#### +######..##### +....#.####### +#.#######.... +.###...#.#..# diff --git a/src/day-13.lisp b/src/day-13.lisp @@ -0,0 +1,38 @@ +(defpackage #:aoc/day-13 + (:use #:cl #:aoc/utils) + (:export #:day-13)) +(in-package #:aoc/day-13) + +(defun find-vertical-point-of-reflection (map) + (loop with width = (input-map-width map) + with height = (input-map-height map) + for reflection-x from 0 below (1- width) + for reflection-length = (min (1+ reflection-x) + (- width reflection-x 1)) + when (loop repeat reflection-length + for x-1 downfrom reflection-x + for x-2 from (1+ reflection-x) + always (loop for y from 0 below height + always (char= (map-cell map (cons x-1 y)) + (map-cell map (cons x-2 y))))) + do (return (1+ reflection-x)))) + +(defun find-horizontal-point-of-reflection (map) + (loop with width = (input-map-width map) + with height = (input-map-height map) + for reflection-y from 0 below (1- height) + for reflection-length = (min (1+ reflection-y) + (- height reflection-y 1)) + when (loop repeat reflection-length + for y-1 downfrom reflection-y + for y-2 from (1+ reflection-y) + always (loop for x from 0 below width + always (char= (map-cell map (cons x y-1)) + (map-cell map (cons x y-2))))) + do (return (1+ reflection-y)))) + +(defun day-13 (input) + (loop for map = (make-map input) + while map + sum (or (find-vertical-point-of-reflection map) + (* (find-horizontal-point-of-reflection map) 100)))) diff --git a/src/utils.lisp b/src/utils.lisp @@ -7,6 +7,7 @@ #:read-input-match #:char-number #:make-map + #:print-map #:input-map #:input-map-width #:input-map-height @@ -94,13 +95,18 @@ with data = nil for row = (read-line input nil) for height from 0 - while row + while (and row (> (length row) 0)) when (= height 0) do (setf width (length row)) do (push row data) - finally (return (make-input-map :data (coerce (nreverse data) 'vector) - :width width - :height height)))) + finally (return (and data + (make-input-map :data (coerce (nreverse data) 'vector) + :width width + :height height))))) + +(defun print-map (map &key (stream *standard-output*)) + (loop for y from 0 below (input-map-height map) + do (format stream "~A~%" (aref (input-map-data map) y)))) (declaim (inline point+ point- point-x point-y) (ftype (function (cons) fixnum) point-x point-y)) diff --git a/t/day-13.lisp b/t/day-13.lisp @@ -0,0 +1,23 @@ +(defpackage #:aoc-test/day-13 + (:use #:cl #:lisp-unit2)) +(in-package #:aoc-test/day-13) + +(define-test test-day-13 + () + (multiple-value-bind (task-1 task-2) + (aoc:run-day 13 "#.##..##. +..#.##.#. +##......# +##......# +..#.##.#. +..##..##. +#.#.##.#. + +#...##..# +#....#..# +..##..### +#####.##. +#####.##. +..##..### +#....#..#") + (assert= 405 task-1)))