diff options
author | Oscar Najera <hi@oscarnajera.com> | 2022-12-19 05:07:07 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2022-12-19 05:07:07 +0100 |
commit | 6970fcacf00860cf6b7ab04b61c58dc2935d53c4 (patch) | |
tree | c28df0d2d4ef9d3b2c53a5fcb7595cda87429764 /AoC2022 | |
parent | 7a756c8ef8d4afc134430752580f89e893baf2d6 (diff) | |
download | scratch-6970fcacf00860cf6b7ab04b61c58dc2935d53c4.tar.gz scratch-6970fcacf00860cf6b7ab04b61c58dc2935d53c4.tar.bz2 scratch-6970fcacf00860cf6b7ab04b61c58dc2935d53c4.zip |
denest more
Diffstat (limited to 'AoC2022')
-rw-r--r-- | AoC2022/16/solver.lisp | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/AoC2022/16/solver.lisp b/AoC2022/16/solver.lisp index 9d07505..158704d 100644 --- a/AoC2022/16/solver.lisp +++ b/AoC2022/16/solver.lisp @@ -105,34 +105,36 @@ (and (zerop (logand next-node-name open)) (< (1+ time-there) time-left)))) - (defun traverse (graph actor open) (if (loop for ac in actor :always (zerop (cadr ac))) (mapcar (lambda (a) (cons (reverse (car a)) (cdr a))) actor) - (destructuring-bind (path time-left previous-flow) (car actor) - (let* ((current-options (assoc (car path) graph :test #'=)) - (flow-released (caddr current-options)) - (current-flow (+ previous-flow (* flow-released time-left))) - (next (remove-if-not (lambda (node) - (appropriate node open time-left)) - (cdddr current-options)))) - (if (null next) - (traverse graph - (append (cdr actor) - (list (list path 0 current-flow))) - open) - - (arrows:-> - (loop for (name . time-there) in next - collect - (let ((time-left (- time-left time-there 1))) - (traverse graph - (append (cdr actor) (list (list (cons name path) time-left - current-flow))) - (logior name open)))) - (sort #'>= :key #'accumulated-flow) - (car))))))) + (advance graph actor open))) + +(defun advance (graph actor open) + (destructuring-bind (path time-left previous-flow) (car actor) + (let* ((current-options (assoc (car path) graph :test #'=)) + (flow-released (caddr current-options)) + (current-flow (+ previous-flow (* flow-released time-left))) + (next (remove-if-not (lambda (node) + (appropriate node open time-left)) + (cdddr current-options)))) + (if (null next) + (traverse graph + (append (cdr actor) + (list (list path 0 current-flow))) + open) + + (arrows:-> + (loop for (name . time-there) in next + collect + (let ((time-left (- time-left time-there 1))) + (traverse graph + (append (cdr actor) (list (list (cons name path) time-left + current-flow))) + (logior name open)))) + (sort #'>= :key #'accumulated-flow) + (car)))))) (defun solver (filename start-time actors) (let* ((action-graph (worthwhile-graph (data filename))) |