aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2022-12-19 14:20:19 +0100
committerOscar Najera <hi@oscarnajera.com>2022-12-19 14:20:19 +0100
commit067c433611309f4e752f2862b04f91b112b3b287 (patch)
tree66296fdc043a41e7b11c420d7942ba4d6e54d9d4
parentd041eafc94868dd0d63069644df34fa505c04b3e (diff)
downloadscratch-067c433611309f4e752f2862b04f91b112b3b287.tar.gz
scratch-067c433611309f4e752f2862b04f91b112b3b287.tar.bz2
scratch-067c433611309f4e752f2862b04f91b112b3b287.zip
reduce no loop
-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)))