commit 62d7d1bf1637ff442375c27eebc0fbf4b56a227a from: Lukas Henkel date: Wed Dec 13 06:14:14 2023 UTC Exit early when finding imperfections commit - b8b8d275ff830707681c11abb59307006a08ffba commit + 62d7d1bf1637ff442375c27eebc0fbf4b56a227a blob - 8aaccfd42317e110dbe98ef60c66c44127c40cf5 blob + 6104d870771ce13cbf9181399fb8c2d4eb514659 --- src/day-13.lisp +++ 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)