diff options
Diffstat (limited to 'AoC2022/18')
-rw-r--r-- | AoC2022/18/solver.lisp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/AoC2022/18/solver.lisp b/AoC2022/18/solver.lisp index 778843d..91397ec 100644 --- a/AoC2022/18/solver.lisp +++ b/AoC2022/18/solver.lisp @@ -39,17 +39,22 @@ (defconstant +neighbor-dirs+ '((1 0 0) (0 1 0) (0 0 1) (-1 0 0) (0 -1 0) (0 0 -1))) -(defun spread-steam (next outer-region cubes min-point max-point) +(defun spread-steam (next allowedp) (loop for dir in +neighbor-dirs+ for nbg = (mapcar #'+ next dir) - when (and (every #'<= min-point nbg max-point) - (not (member nbg cubes :test #'equal)) - (not (member nbg outer-region :test #'equal))) + when (funcall allowedp nbg) collect nbg)) +(defun available-p (cubes min-point max-point) + (lambda (point) + (and (every #'<= min-point point max-point) + (not (member point cubes :test #'equal))))) + (defun fill-outside (queue outer-region cubes min-point max-point) (reduce (lambda (out voxel) - (let ((next-queue (spread-steam voxel out cubes min-point max-point))) + (let ((next-queue (spread-steam voxel + (available-p + (append out cubes) min-point max-point)))) (fill-outside next-queue (append next-queue out) cubes min-point max-point))) |