From 07f009aef0270675ebdb2b2f7667515c8e6fbe14 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Tue, 13 Dec 2022 04:15:38 +0100 Subject: flet --- AoC2022/12/solver.lisp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'AoC2022/12/solver.lisp') 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) -- cgit v1.2.3