aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AoC2022/12/solver.lisp16
1 files changed, 7 insertions, 9 deletions
diff --git a/AoC2022/12/solver.lisp b/AoC2022/12/solver.lisp
index f4fd602..3297fd5 100644
--- a/AoC2022/12/solver.lisp
+++ b/AoC2022/12/solver.lisp
@@ -28,15 +28,13 @@
(make-land :elevation (map 'vector #'elevation (apply #'concatenate 'string data))
:neighbors (possible-directions (length (car data)) (length data)))))
-(defun appropriate (place current land paths)
- (and (not (gethash place paths)) ;; not visited
- (>= 1 (- (aref (land-elevation land) place)
- (aref (land-elevation land) current)))
- (setf (gethash place paths) (cons place (gethash current paths)))))
-
-(defun next-steps (place land paths)
- (remove-if-not (lambda (option) (appropriate option place land paths))
- (funcall (land-neighbors land) place)))
+(defun next-steps (current land paths)
+ (flet ((appropriate (next)
+ (and (not (gethash next paths)) ;; not visited
+ (>= 1 (- (aref (land-elevation land) next)
+ (aref (land-elevation land) current)))
+ (setf (gethash next paths) (cons next (gethash current paths))))))
+ (remove-if-not #'appropriate (funcall (land-neighbors land) current))))
(defun shortest-path (starts land paths)
(unless (null starts)