about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--day1527
-rw-r--r--day15.rkt50
2 files changed, 77 insertions, 0 deletions
diff --git a/day15 b/day15
new file mode 100644
index 0000000..ea493e7
--- /dev/null
+++ b/day15
@@ -0,0 +1,27 @@
+Sensor at x=1326566, y=3575946: closest beacon is at x=1374835, y=2000000
+Sensor at x=2681168, y=3951549: closest beacon is at x=3184941, y=3924923
+Sensor at x=3959984, y=1095746: closest beacon is at x=3621412, y=2239432
+Sensor at x=3150886, y=2479946: closest beacon is at x=3621412, y=2239432
+Sensor at x=3983027, y=2972336: closest beacon is at x=4012908, y=3083616
+Sensor at x=3371601, y=3853300: closest beacon is at x=3184941, y=3924923
+Sensor at x=3174612, y=3992719: closest beacon is at x=3184941, y=3924923
+Sensor at x=3316368, y=1503688: closest beacon is at x=3621412, y=2239432
+Sensor at x=3818181, y=2331216: closest beacon is at x=3621412, y=2239432
+Sensor at x=3960526, y=3229321: closest beacon is at x=4012908, y=3083616
+Sensor at x=61030, y=3045273: closest beacon is at x=-467419, y=2369316
+Sensor at x=3635583, y=3121524: closest beacon is at x=4012908, y=3083616
+Sensor at x=2813357, y=5535: closest beacon is at x=3595763, y=-77322
+Sensor at x=382745, y=1566522: closest beacon is at x=1374835, y=2000000
+Sensor at x=3585664, y=538632: closest beacon is at x=3595763, y=-77322
+Sensor at x=3979654, y=2158646: closest beacon is at x=3621412, y=2239432
+Sensor at x=3996588, y=2833167: closest beacon is at x=4012908, y=3083616
+Sensor at x=3249383, y=141800: closest beacon is at x=3595763, y=-77322
+Sensor at x=3847114, y=225529: closest beacon is at x=3595763, y=-77322
+Sensor at x=3668737, y=3720078: closest beacon is at x=3184941, y=3924923
+Sensor at x=1761961, y=680560: closest beacon is at x=1374835, y=2000000
+Sensor at x=2556636, y=2213691: closest beacon is at x=3621412, y=2239432
+Sensor at x=65365, y=215977: closest beacon is at x=346716, y=-573228
+Sensor at x=709928, y=2270200: closest beacon is at x=1374835, y=2000000
+Sensor at x=3673956, y=2670437: closest beacon is at x=4029651, y=2547743
+Sensor at x=3250958, y=3999227: closest beacon is at x=3184941, y=3924923
+Sensor at x=3009537, y=3292368: closest beacon is at x=3184941, y=3924923
diff --git a/day15.rkt b/day15.rkt
new file mode 100644
index 0000000..c31b64a
--- /dev/null
+++ b/day15.rkt
@@ -0,0 +1,50 @@
+#lang racket
+;; ala https://github.com/narimiran/AdventOfCode2022/blob/main/clojure/day15.clj
+
+(define data
+  (for/list ([line (file->lines "day15")])
+    (map string->number (regexp-match* #rx"[0-9]+" line))))
+
+(define (dist x1 y1 x2 y2)
+  (+ (abs (- x1 x2))
+     (abs (- y1 y2))))
+
+(define (seen-in-row row)
+  (append-map (lambda (line)
+                (let* ([sx (first line)]
+                       [sy (second line)]
+                       [r (dist sx sy (third line) (fourth line))]
+                       [d (- r (abs (- row sy)))])
+                  (if (positive? d)
+                    (list (list (- sx d) (+ sx d)))
+                    (list))))
+                data))
+
+(define (part1)
+  (let* ([seen (seen-in-row 2000000)]
+         [a (first (first (sort seen < #:key first)))]
+         [b (second (first (sort seen > #:key second)))])
+    (- b a)))
+
+(part1)
+;; 5147333
+
+(define (find-a-hole seen)
+  (let loop ([highest 0]
+             [seen (sort seen < #:key first)])
+    (if (null? seen)
+      #f
+      (if (<= (caar seen) (+ highest 1))
+        (loop (max highest (cadar seen)) (rest seen))
+        (- (caar seen) 1)))))
+
+(define (part2)
+  (let loop ([row 4000000])
+    (let* ([seen (seen-in-row row)]
+           [hole (find-a-hole seen)])
+      (if hole
+        (+ (* 4000000 hole) row)
+        (loop (- row 1))))))
+
+(part2)
+;; 13734006908372