aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2022-12-17 14:33:07 +0100
committerOscar Najera <hi@oscarnajera.com>2022-12-17 14:33:07 +0100
commitc74421bcc04262ca88d105d1ebf7695ed5b07f43 (patch)
tree0bd2031fc5d98102b6adc47ca2a2146a4f4ae362 /AoC2022
parentba0be37eb3716228bbdbc3158146ceeeb9c389a9 (diff)
downloadscratch-c74421bcc04262ca88d105d1ebf7695ed5b07f43.tar.gz
scratch-c74421bcc04262ca88d105d1ebf7695ed5b07f43.tar.bz2
scratch-c74421bcc04262ca88d105d1ebf7695ed5b07f43.zip
no record vector on counter
Diffstat (limited to 'AoC2022')
-rw-r--r--AoC2022/15/solver.lisp26
1 files changed, 9 insertions, 17 deletions
diff --git a/AoC2022/15/solver.lisp b/AoC2022/15/solver.lisp
index 9a93e1f..3471b3b 100644
--- a/AoC2022/15/solver.lisp
+++ b/AoC2022/15/solver.lisp
@@ -85,25 +85,17 @@
(let ((bounds (bounds markers))
(max-distance (loop for (sensor beacon) on markers by #'cddr
maximize (manhattan-dist sensor beacon))))
-
(destructuring-bind ((xmin xmax) ys) bounds
(declare (ignore ys))
- (let* ((stride (- (+ (* 2 max-distance) xmax 1) xmin))
- (row-min (- xmin max-distance))
- (row (make-array stride :element-type '(unsigned-byte 1) :initial-element 0)))
- (loop for (sensor beacon) on markers by #'cddr
- for distance = (manhattan-dist sensor beacon)
- when (= target-row (cdr sensor))
- do (setf (aref row (- (car sensor) row-min)) 1)
- when (= target-row (cdr beacon))
- do (setf (aref row (- (car beacon) row-min)) 1)
-
- sum (loop
- for x from (- xmin distance) to (+ xmax distance)
- when (and (<= (manhattan-dist sensor (cons x target-row)) distance)
- (< -1 (- x row-min) stride)
- (= 0 (aref row (- x row-min))))
- count it and do (setf (aref row (- x row-min)) 1)))))))
+ (loop with y = target-row
+ for x from (- xmin max-distance) to (+ xmax max-distance)
+ :count (loop for (sensor beacon) on markers by #'cddr
+ :thereis (and (not (equal beacon (cons x y)))
+ (not (equal sensor (cons x y)))
+ (<= (manhattan-dist sensor (cons x y))
+ (manhattan-dist sensor beacon))))))))
+
+
(count-cover (markers (uiop:read-file-lines "eg-in")) 10)
(count-cover (markers (uiop:read-file-lines "input")) 2000000)