advent-of-code-2023

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

commit 62d7d1bf1637ff442375c27eebc0fbf4b56a227a
parent b8b8d275ff830707681c11abb59307006a08ffba
Author: Lukas Henkel <lh@entf.net>
Date:   Wed, 13 Dec 2023 07:14:14 +0100

Exit early when finding imperfections

Diffstat:
Msrc/day-13.lisp | 17++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/day-13.lisp b/src/day-13.lisp @@ -19,16 +19,19 @@ (defun find-reflection-imperfections (map reflection-point primary-axis-length secondary-axis-length make-point) (loop with reflection-length = (min (1+ reflection-point) (- primary-axis-length reflection-point 1)) + with imperfections = 0 repeat reflection-length for compare-1 downfrom reflection-point for compare-2 from (1+ reflection-point) - for reflection-matches = (loop for secondary-axis-point from 0 below secondary-axis-length - for point-1 = (funcall make-point compare-1 secondary-axis-point) - for point-2 = (funcall make-point compare-2 secondary-axis-point) - when (char= (map-cell map point-1) - (map-cell map point-2)) - sum 1) - sum (- secondary-axis-length reflection-matches))) + while (<= imperfections 1) + do (loop for secondary-axis-point from 0 below secondary-axis-length + for point-1 = (funcall make-point compare-1 secondary-axis-point) + for point-2 = (funcall make-point compare-2 secondary-axis-point) + when (char/= (map-cell map point-1) + (map-cell map point-2)) + do (incf imperfections) + while (<= imperfections 1)) + finally (return imperfections))) (defun find-point-of-reflection (map type) (multiple-value-bind (primary-axis-length secondary-axis-length make-point)