From ea7e004919bb64c27f3dde76af7e020d7f06b519 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Thu, 14 Dec 2023 09:30:04 +0100 Subject: reorder refactor --- AoC2023/day10/solver.lisp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'AoC2023/day10/solver.lisp') diff --git a/AoC2023/day10/solver.lisp b/AoC2023/day10/solver.lisp index 11bd41c..1abe7ef 100644 --- a/AoC2023/day10/solver.lisp +++ b/AoC2023/day10/solver.lisp @@ -1,6 +1,6 @@ ;;05:32 -(ql:quickload '(fiveam)) +(ql:quickload '(fiveam arrows)) (defparameter directions '((up -1 0) @@ -81,8 +81,6 @@ LJ.LJ") (gethash next loop-tiles) t) until (equal next start)) loop-tiles)) -;; (get-loop -;; (uiop:split-string eg-input :separator '(#\Newline))) (defun solver1 (rows) (let ((map (make-array (length rows) :initial-contents rows))) @@ -95,19 +93,19 @@ LJ.LJ") ;; those 2 cells taking the point a bit lower, would mean only counting pipes ;; with down component thus F,|,7. The rest L,-,J are irrelevant. -(defun rassoc-get (item list) +(defun rassoc-get (list item) (car (rassoc item list :test #'equal))) (defun correct-start (map) (let ((start (find-start map))) - (setf (aref (aref map (car start)) (cadr start)) - (rassoc-get - (loop for (y x) in (start-neighbors map start) - collect - (rassoc-get (list (- y (first start)) - (- x (second start))) - directions)) - pipes)))) + (arrows:->> (start-neighbors map start) + (mapcar (lambda (point) + (destructuring-bind (y x) point + (list (- y (first start)) + (- x (second start)))))) + (mapcar (lambda (p) (rassoc-get directions p))) + (rassoc-get pipes) + (setf (aref (aref map (car start)) (cadr start)))))) (defun solver2 (rows) (let* ((map (make-array (length rows) :initial-contents rows)) -- cgit v1.2.3