aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2023
diff options
context:
space:
mode:
Diffstat (limited to 'AoC2023')
-rw-r--r--AoC2023/day10/solver.lisp22
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))