aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/16
diff options
context:
space:
mode:
Diffstat (limited to 'AoC2022/16')
-rw-r--r--AoC2022/16/solver.lisp21
1 files changed, 12 insertions, 9 deletions
diff --git a/AoC2022/16/solver.lisp b/AoC2022/16/solver.lisp
index 7cf28b6..e2addaf 100644
--- a/AoC2022/16/solver.lisp
+++ b/AoC2022/16/solver.lisp
@@ -128,15 +128,18 @@
(append (cdr actor)
(list (list path 0 current-flow)))
open)
-
- (reduce (lambda (acc term)
- (if (>= (accumulated-flow acc) (accumulated-flow term))
- acc term))
- (loop for (node . actor-next-move) in next
- collect
- (traverse graph
- (append (cdr actor) actor-next-move)
- (logior node open))))))))
+ (reduce
+ (lambda (acc term)
+ (let ((acc-flow (accumulated-flow acc))
+ (next-actors
+ (destructuring-bind (node . actor-next-move) term
+ (traverse graph
+ (append (cdr actor) actor-next-move)
+ (logior node open)))))
+ (if (>= acc-flow (accumulated-flow next-actors))
+ acc next-actors)))
+
+ next :initial-value nil)))))
(defun solver (filename start-time actors)
(let* ((action-graph (worthwhile-graph (data filename)))