diff options
author | Oscar Najera <hi@oscarnajera.com> | 2023-12-14 09:30:04 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2023-12-14 09:31:24 +0100 |
commit | ea7e004919bb64c27f3dde76af7e020d7f06b519 (patch) | |
tree | 8cf01c00da790b6b8138cd92b453ccdfa21d5331 /AoC2023/day10 | |
parent | bd3d108d004bd2322f3b4b8d4e2cfcf1044dadfb (diff) | |
download | scratch-ea7e004919bb64c27f3dde76af7e020d7f06b519.tar.gz scratch-ea7e004919bb64c27f3dde76af7e020d7f06b519.tar.bz2 scratch-ea7e004919bb64c27f3dde76af7e020d7f06b519.zip |
reorder refactor
Diffstat (limited to 'AoC2023/day10')
-rw-r--r-- | AoC2023/day10/solver.lisp | 22 |
1 files changed, 10 insertions, 12 deletions
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)) |