From d041eafc94868dd0d63069644df34fa505c04b3e Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Mon, 19 Dec 2022 13:34:29 +0100 Subject: reduce instead of sort --- AoC2022/16/solver.lisp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'AoC2022') diff --git a/AoC2022/16/solver.lisp b/AoC2022/16/solver.lisp index 6f0f254..7cf28b6 100644 --- a/AoC2022/16/solver.lisp +++ b/AoC2022/16/solver.lisp @@ -110,7 +110,6 @@ ;; ) - (defun advance (graph actor open) (destructuring-bind (path time-left previous-flow) (car actor) (let* ((current-options (assoc (car path) graph :test #'=)) @@ -130,14 +129,14 @@ (list (list path 0 current-flow))) open) - (arrows:-> + (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))) - (sort #'>= :key #'accumulated-flow) - (car)))))) + (logior node open)))))))) (defun solver (filename start-time actors) (let* ((action-graph (worthwhile-graph (data filename))) -- cgit v1.2.3