🎄⌨️ Advent of Code 2018

Diff

Differences From Artifact [124443]:

To Artifact [266d98]:


99
100
101
102
103
104
105
106
107


108
109
110
111
112
113
114
115
116
117




118
119
120
121
122
123
124
99
100
101
102
103
104
105


106
107
108
109
110
111
112





113
114
115
116
117
118
119
120
121
122
123







-
-
+
+





-
-
-
-
-
+
+
+
+







                  [else (cons ch lst)])))))

;; Is point p inside grid g? Film at 11
(define (inside-grid? g p)
  (match-define (posn px py) p)
  (and (>= px 0)
       (>= py 0)
       (< px (grid-rows g))
       (< py (grid-cols g))))
       (< px (grid-cols g))
       (< py (grid-rows g))))

;; Get a list of a positions neighboring points, ensuring none are out of bounds
(define (neighbor-coords g pos)
  (match-define (posn x y) pos)
  (filter (curry inside-grid? g)
          (map (lambda (lst) (apply posn lst))
               `((,(- x 1) ,y)
                 (,x ,(+ y 1))
                 (,(+ x 1) ,y)
                 (,x ,(- y 1))))))
          (list (posn (- x 1) y)
                (posn x (+ y 1))
                (posn (+ x 1) y)
                (posn x (- y 1)))))

;; Get all the EMPTY neighboring points of a given spot OR list of spots.
;; If a (listof posn?) is passed, ensures the returned list does not include
;; any of the original positions.
(define (free-neighbors-at world pos)
  (cond [(posn? pos)
         (~> (neighbor-coords world pos)