diff options
author | Oscar Najera <hi@oscarnajera.com> | 2022-12-19 13:34:29 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2022-12-19 13:34:29 +0100 |
commit | d041eafc94868dd0d63069644df34fa505c04b3e (patch) | |
tree | 218a5f9bb3f41fb148b4c499c7b3914c6414e0f6 /AoC2022 | |
parent | 6c39f4526fed2c271a909cbd6b3f48f5b25f28ae (diff) | |
download | scratch-d041eafc94868dd0d63069644df34fa505c04b3e.tar.gz scratch-d041eafc94868dd0d63069644df34fa505c04b3e.tar.bz2 scratch-d041eafc94868dd0d63069644df34fa505c04b3e.zip |
reduce instead of sort
Diffstat (limited to 'AoC2022')
-rw-r--r-- | AoC2022/16/solver.lisp | 9 |
1 files changed, 4 insertions, 5 deletions
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))) |