day 15 part 2. using INTERVALS

This commit is contained in:
efim
2022-12-16 15:30:38 +00:00
parent 190382eddc
commit c2ea2ec16e
2 changed files with 334 additions and 1 deletions

View File

@@ -18,6 +18,10 @@
(and (= (x left) (x right))
(= (y left) (y right))))
(defmethod manh-dist ((one point) (two point))
(+ (abs (- (x one) (x two)))
(abs (- (y one) (y two)))))
(defclass sensor ()
((self-coord :initarg :self :reader self-coord)
@@ -93,7 +97,7 @@
do (format t "iterating for x:~a y:~a~%" x to-check-y))))))
(count-certainly-not-beacons "day15-test.txt")
(count-certainly-not-beacons "day15-input.txt")
;; (count-certainly-not-beacons "day15-input.txt")
;; well, that's just too slow
;; how do i rewrite it to make it faster?
@@ -112,3 +116,36 @@
;; nope, even if it were 5 minutes for 16mil,
;; so 2 minutes per 4 mil, then multiply by 4M - more than a day.
;; think better
(defun subtract-interval (minuend subtrahend)
(if (not subtrahend)
(list minuend) ; list of one interval
(destructuring-bind ((m-left m-right) (s-left s-right)) (list minuend subtrahend)
(cond
((< m-right s-left)
(list (list m-left m-right))) ; minuend fully to the left
((> m-left s-right)
(list (list m-left m-right))) ; minuend fully to the right
((and (< m-left s-left)
(> m-right s-right)) ; minuend is around subtrahend
(list (list m-left (1- s-left))
(list (1+ s-right) m-right))) ; part before and after subtrahend
((and (>= m-left s-left)
(<= m-right s-right)) ; subtrahend consumes minuend
nil)
((< m-left s-left) ; minuend start to the left, but not subtrahend consumes all right part
(list (list m-left (1- s-left)))) ; list of one interval
((> m-right s-right) ; minuend has part to the right of subtrahend
(list (list (1+ s-right) m-right)))))))
(defun get-no-unknown-beacons-x-interval (line-y scanner)
(let* ((y-dist (abs (- line-y (y (self-coord scanner)))))
(x-slack (- (covered-dist scanner) y-dist))
(x-sc (x (self-coord scanner))))
(when (>= x-slack 0)
(list (- x-sc x-slack) (+ x-sc x-slack)))))
(defun subtract-from-all (intervals subtrahend)
(mapcan (lambda (interval) (subtract-interval interval subtrahend))
intervals))