aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2022-12-13 04:15:38 +0100
committerOscar Najera <hi@oscarnajera.com>2022-12-13 04:15:38 +0100
commit07f009aef0270675ebdb2b2f7667515c8e6fbe14 (patch)
tree5bac0d65bec865fe18e2d57c743d557155a0d69b
parent40a24a4f53c8c4940e299f3adc3a18e1c06f0866 (diff)
downloadscratch-07f009aef0270675ebdb2b2f7667515c8e6fbe14.tar.gz
scratch-07f009aef0270675ebdb2b2f7667515c8e6fbe14.tar.bz2
scratch-07f009aef0270675ebdb2b2f7667515c8e6fbe14.zip
flet
-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)