From 067c433611309f4e752f2862b04f91b112b3b287 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Mon, 19 Dec 2022 14:20:19 +0100 Subject: reduce no loop --- AoC2022/16/solver.lisp | 21 ++++++++++++--------- 1 file 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))) -- cgit v1.2.3