Advent-of-Code-2018 icon indicating copy to clipboard operation
Advent-of-Code-2018 copied to clipboard

Advent of Code 2018 in Emacs Lisp

-- eval: (toc-org-mode); --

#+TITLE: Advent of Code 2018 in Emacs Lisp

#+PROPERTY: header-args:elisp :lexical t

  • Table of Contents :TOC:QUOTE: #+BEGIN_QUOTE
  • [[#day-1-chronal-calibration][Day 1: Chronal Calibration]]
    • [[#part-one][Part One]]
    • [[#part-two][Part Two]]
  • [[#day-2-inventory-management-system][Day 2: Inventory Management System]]
    • [[#part-one-1][Part one]]
    • [[#part-two-1][Part Two]]
  • [[#day-3-no-matter-how-you-slice-it][Day 3: No Matter How You Slice it]]
    • [[#part-one-2][Part One]]
    • [[#part-two-2][Part Two]]
  • [[#day-4-repose-record][Day 4: Repose Record]]
    • [[#part-one-3][Part One]]
    • [[#part-two-3][Part Two]]
  • [[#day-5-alchemical-reduction][Day 5: Alchemical Reduction]]
    • [[#part-one-4][Part One]]
    • [[#part-two-4][Part Two]]
  • [[#day-6-chronal-coordinates][Day 6: Chronal Coordinates]]
    • [[#part-one-5][Part One]]
    • [[#part-two-5][Part Two]] #+END_QUOTE
  • Day 1: Chronal Calibration

** Part One

#+BEGIN_SRC elisp (defun advent-of-code-2018-1-1 (input-file) (interactive "fInput file: ") (with-temp-buffer (insert-file-contents input-file) (goto-char (point-min)) (let ((frequency 0) change) (while (setq change (ignore-errors (read (current-buffer)))) (setq frequency (+ frequency change))) (kill-new (format "%d" frequency)) (message "Copied: %d" frequency)))) #+END_SRC

** Part Two

#+NAME: tb1 | Changes | Answer | |--------------------+--------| | +1, -1 | 0 | | +3, +3, +4, -2, -4 | 10 | | -6, +3, +8, +5, -6 | 5 | | +7, +7, -2, -7, -4 | 14 |

#+BEGIN_SRC elisp (defun advent-of-code-2018-1-2-subr (changes) (let ((frequencies (list 0)) (cursor changes) frequency) (catch 'found (while t (setq frequency (+ (car frequencies) (car cursor))) (when (memq frequency frequencies) (throw 'found frequency)) (push frequency frequencies) (setq cursor (or (cdr cursor) changes)))))) #+END_SRC

#+RESULTS: : advent-of-code-2018-1-2-subr

Test the function against the above table:

#+BEGIN_SRC elisp :var data=tb1[,0] (let ((list-of-changes (mapcar (lambda (s) (mapcar #'string-to-number (split-string s ", " t))) data))) (mapcar #'advent-of-code-2018-1-2-subr list-of-changes)) #+END_SRC

#+RESULTS: | 0 | 10 | 5 | 14 |

#+BEGIN_SRC elisp (defun advent-of-code-2018-1-2 (input-file) (interactive "fInput file: ") (let* ((changes (with-temp-buffer (insert-file-contents input-file) (mapcar #'string-to-number (split-string (buffer-string) "\n" 'omit-nulls)))) (frequency (advent-of-code-2018-1-2-subr changes))) (kill-new (format "%d" frequency)) (message "Copied: %d" frequency))) #+END_SRC

#+RESULTS: : advent-of-code-2018-1-2

It takes 48.060945s with my input file.

  • Day 2: Inventory Management System

** Part one

#+NAME: day2-tb1

ID
abcdef
bababc
abbcde
abcccd
aabcdd
abcdee
ababab

#+BEGIN_SRC elisp :var data=day2-tb1[,0] :results pp (let ((twos 0) (threes 0)) (dolist (input data) (let ((lst (string-to-list input))) (when (cl-find-if (lambda (item) (= 2 (cl-count item lst))) lst) (cl-incf twos)) (when (cl-find-if (lambda (item) (= 3 (cl-count item lst))) lst) (cl-incf threes)))) (* twos threes)) #+END_SRC

#+RESULTS: : 12

#+BEGIN_SRC elisp (defun advent-of-code-2018-2-1 (input-file) (interactive "fInput File: ") (let ((input-lines (with-temp-buffer (insert-file-contents input-file) (split-string (buffer-string) "\n" 'omit-nulls)))) (let ((twos 0) (threes 0)) (dolist (input input-lines) (let ((lst (string-to-list input))) (when (cl-find-if (lambda (item) (= 2 (cl-count item lst))) lst) (cl-incf twos)) (when (cl-find-if (lambda (item) (= 3 (cl-count item lst))) lst) (cl-incf threes)))) (message "Answer: %s" (* twos threes))))) #+END_SRC

#+RESULTS: : advent-of-code-2018-2-1

** Part Two

helper 1

#+BEGIN_SRC elisp (defun advent-of-code-2018-2-2-combinations (list) (let ((i 0) result) (while (< i (length list)) (let ((j (1+ i))) (while (< j (length list)) (push (cons (nth i list) (nth j list)) result) (cl-incf j))) (cl-incf i)) (nreverse result))) #+END_SRC

#+RESULTS: : advent-of-code-2018-2-2-combinations

test helper 1

#+BEGIN_SRC elisp (advent-of-code-2018-2-2-combinations '(a b c)) #+END_SRC

#+RESULTS: : ((a . b) (a . c) (b . c))

helper 2

#+BEGIN_SRC elisp (defun advent-of-code-2018-2-2-subr (ids) (cl-some (pcase-lambda (`(,id1 . ,id2)) (cl-assert (= (length id1) (length id2))) (let ((diffs 0) pos) (dotimes (i (length id1)) (when (/= (elt id1 i) (elt id2 i)) (setq pos i) (cl-incf diffs))) (when (= diffs 1) (concat (substring id1 0 pos) (substring id1 (1+ pos)))))) (advent-of-code-2018-2-2-combinations ids))) #+END_SRC

#+RESULTS: : advent-of-code-2018-2-2-subr

test helper 2

#+NAME: day2-tb2

ID
abcde
fghij
klmno
pqrst
fguij
axcye
wvxyz

#+BEGIN_SRC elisp :var data=day2-tb2[,0] (advent-of-code-2018-2-2-subr data) #+END_SRC

#+RESULTS: : fgij

#+BEGIN_SRC elisp (defun advent-of-code-2018-2-2 (input-file) (interactive "fInput File: ") (let ((input-lines (with-temp-buffer (insert-file-contents input-file) (split-string (buffer-string) "\n" 'omit-nulls)))) (message "Answer: %s" (advent-of-code-2018-2-2-subr input-lines)))) #+END_SRC

#+RESULTS: : advent-of-code-2018-2-2

  • Day 3: No Matter How You Slice it

** Part One

#+NAME: day3-table-1 | #1 @ 1,3: 4x4 | | #2 @ 3,1: 4x4 | | #3 @ 5,5: 2x2 |

Parse input

#+BEGIN_SRC elisp (defun advent-of-code-2018-3-1-parse (inputs) (let ((regexp (replace-regexp-in-string "" (rx (group (1+ num))) ;; #1 @ 1,3: 4x4 "# @ ,: x" nil 'literal))) (mapcar (lambda (s) (cl-assert (string-match regexp s)) (list :id (string-to-number (match-string 1 s)) :left (string-to-number (match-string 2 s)) :top (string-to-number (match-string 3 s)) :wide (string-to-number (match-string 4 s)) :tall (string-to-number (match-string 5 s)))) inputs))) #+END_SRC

#+RESULTS: : advent-of-code-2018-3-1-parse

#+BEGIN_SRC elisp :var data=day3-table-1[,0] (advent-of-code-2018-3-1-parse data) #+END_SRC

#+RESULTS: | :id | 1 | :left | 1 | :top | 3 | :wide | 4 | :tall | 4 | | :id | 2 | :left | 3 | :top | 1 | :wide | 4 | :tall | 4 | | :id | 3 | :left | 5 | :top | 5 | :wide | 2 | :tall | 2 |

Area

#+BEGIN_SRC elisp (defun advent-of-code-2018-3-1-area (data) (list :width (apply #'max (mapcar (lambda (pl) (+ (plist-get pl :left) (plist-get pl :wide))) data)) :height (apply #'max (mapcar (lambda (pl) (+ (plist-get pl :top) (plist-get pl :tall))) data)))) #+END_SRC

#+RESULTS: : advent-of-code-2018-3-1-area

#+BEGIN_SRC elisp :var data=day3-table-1[,0] (advent-of-code-2018-3-1-area (advent-of-code-2018-3-1-parse data)) #+END_SRC

#+RESULTS: | :width | 7 | :height | 7 |

#+BEGIN_SRC elisp (defun advent-of-code-2018-3-1-make-vector (width height) (let ((vec (make-vector height nil))) (dotimes (i height vec) (setf (elt vec i) (make-vector width 0)))))

(defun advent-of-code-2018-3-1-subr (inputs) (let* ((claims (advent-of-code-2018-3-1-parse inputs)) (area (advent-of-code-2018-3-1-area claims)) (height (plist-get area :height)) (width (plist-get area :width)) (vv (advent-of-code-2018-3-1-make-vector width height))) (dolist (claim claims) (let ((x (plist-get claim :left)) (y (plist-get claim :top))) (dotimes (i (plist-get claim :wide)) (dotimes (j (plist-get claim :tall)) (cl-incf (elt (elt vv (+ y j)) (+ x i))))))) (let ((count 0)) (dotimes (i width count) (dotimes (j height) (when (> (elt (elt vv i) j) 1) (cl-incf count))))))) #+END_SRC

#+RESULTS: : advent-of-code-2018-3-1-subr

#+BEGIN_SRC elisp :var inputs=day3-table-1[,0] (advent-of-code-2018-3-1-subr inputs) #+END_SRC

#+RESULTS: : 4

#+BEGIN_SRC elisp (defun advent-of-code-2018-3-1 (input-file) (interactive "fInput file: ") (let ((input-lines (with-temp-buffer (insert-file-contents input-file) (split-string (buffer-string) "\n" t)))) (message "Answer: %s" (advent-of-code-2018-3-1-subr input-lines)))) #+END_SRC

#+RESULTS: : advent-of-code-2018-3-1

** Part Two

#+BEGIN_SRC elisp (defun advent-of-code-2018-3-2-overlap-p (claim vv) (let ((x (plist-get claim :left)) (y (plist-get claim :top))) (catch 'overlap (dotimes (i (plist-get claim :wide)) (dotimes (j (plist-get claim :tall)) (when (> (elt (elt vv (+ y j)) (+ x i)) 1) (throw 'overlap t)))))))

(defun advent-of-code-2018-3-2-subr (inputs) (let* ((claims (advent-of-code-2018-3-1-parse inputs)) (area (advent-of-code-2018-3-1-area claims)) (height (plist-get area :height)) (width (plist-get area :width)) (vv (advent-of-code-2018-3-1-make-vector width height))) (dolist (claim claims) (let ((x (plist-get claim :left)) (y (plist-get claim :top))) (dotimes (i (plist-get claim :wide)) (dotimes (j (plist-get claim :tall)) (cl-incf (elt (elt vv (+ y j)) (+ x i))))))) (let ((claim (cl-find-if-not (lambda (claim) (advent-of-code-2018-3-2-overlap-p claim vv)) claims))) (cl-assert claim) (plist-get claim :id)))) #+END_SRC

#+RESULTS: : advent-of-code-2018-3-2-subr

#+BEGIN_SRC elisp :var inputs=day3-table-1[,0] (advent-of-code-2018-3-2-subr inputs) #+END_SRC

#+RESULTS: : 3

#+BEGIN_SRC elisp (defun advent-of-code-2018-3-2 (input-file) (interactive "fInput file: ") (message "Answer: %s" (advent-of-code-2018-3-2-subr (with-temp-buffer (insert-file-contents input-file) (split-string (buffer-string) "\n" t))))) #+END_SRC

#+RESULTS: : advent-of-code-2018-3-2

#+BEGIN_SRC elisp (advent-of-code-2018-3-2 "inputs/3-2.txt") #+END_SRC

#+RESULTS: : Answer: 331

  • Day 4: Repose Record

** Part One

#+BEGIN_SRC elisp (defun advent-of-code-2018-4-1-parse (input-file) (with-temp-buffer (insert-file-contents input-file) (sort-lines nil (point-min) (point-max)) (goto-char (point-min)) (let (id alist beg end) (while (re-search-forward "Guard #\([0-9]+\)" nil t) (setq id (string-to-number (match-string 1))) (when (eq :null (alist-get id alist :null)) (push (cons id ()) alist)) (while (save-excursion (forward-line 1) (search-forward "falls asleep" (line-end-position) t)) (cl-assert (re-search-forward (rx "00:" (group num num) "] falls asleep"))) (setq beg (string-to-number (match-string 1))) (cl-assert (re-search-forward (rx "00:" (group num num) "] wakes up"))) (setq end (string-to-number (match-string 1))) (push (cons beg end) (alist-get id alist)))) alist)))

(defun advent-of-code-2018-4-1 (input-file) (interactive "fInput file: ") (let* ((parsed (advent-of-code-2018-4-1-parse input-file)) (sorted (sort parsed (lambda (guard1 guard2) (cl-flet ((sum (guard) (apply #'+ (mapcar (pcase-lambda ((,beg . ,end)) (- end beg)) (cdr guard))))) (> (sum guard1) (sum guard2)))))) (guard (car sorted))) (let ((alist (cl-loop for i from 0 to 59 collect (cons i 0)))) (pcase-dolist ((,beg . ,end) (cdr guard)) (cl-loop for i from beg to (1- end) do (cl-incf (alist-get i alist)))) ;; assuming only one max (message "%s" (* (car guard) (car (rassq (apply #'max (mapcar #'cdr alist)) alist))))))) #+END_SRC

#+RESULTS: : advent-of-code-2018-4-1

#+BEGIN_SRC elisp (advent-of-code-2018-4-1 "inputs/4-1.txt") #+END_SRC

#+RESULTS: : 3212

** Part Two

#+BEGIN_SRC elisp (defun advent-of-code-2018-4-2-transform (guard) (let ((alist (cl-loop for i from 0 to 59 collect (cons i 0)))) (pcase-dolist (`(,beg . ,end) (cdr guard)) (cl-loop for i from beg to (1- end) do (cl-incf (alist-get i alist)))) (cons (car guard) (rassq ;; Assuming unique (apply #'max (mapcar #'cdr alist)) alist))))

(defun advent-of-code-2018-4-2 (input-file) (interactive "fInput file: ") (let* ((parsed (advent-of-code-2018-4-1-parse input-file)) (guards (mapcar #'advent-of-code-2018-4-2-transform parsed)) (sorted (sort guards (lambda (guard1 guard2) (> (cddr guard1) (cddr guard2))))) (guard (car sorted)) (id (car guard)) (minute (car (cdr guard)))) (message "%s" (* id minute)))) #+END_SRC

#+RESULTS: : advent-of-code-2018-4-2

#+BEGIN_SRC elisp (advent-of-code-2018-4-2 "inputs/4-2.txt") #+END_SRC

#+RESULTS: : 4966

  • Day 5: Alchemical Reduction

** Part One

#+BEGIN_SRC elisp (with-temp-buffer (insert "dabAcCaCBAcCcaDA") (goto-char (point-min)) (while (< (point) (- (point-max) 2)) (if (= (abs (- (char-after) (char-after (1+ (point))))) (- ?a ?A)) (progn (delete-char 2) (goto-char (point-min))) (forward-char 1))) (buffer-string)) #+END_SRC

#+RESULTS: : dabCBAcaDA

#+BEGIN_SRC elisp (defun advent-of-code-2018-5-1-subr (string) (with-temp-buffer (insert string) (goto-char (point-min)) (let (next) (while (setq next (char-after (1+ (point)))) (if (= (abs (- (char-after) next)) 32) (progn (delete-char 2) (goto-char (1- (point)))) (goto-char (1+ (point)))))) (buffer-string)))

(defun advent-of-code-2018-5-1 (input-file) (interactive "fInput file: ") (length (advent-of-code-2018-5-1-subr ;; Trim the final newline (string-trim-right (with-temp-buffer (insert-file-contents input-file) (buffer-string)))))) #+END_SRC

#+RESULTS: : advent-of-code-2018-5-1

#+BEGIN_SRC elisp (advent-of-code-2018-5-1 "inputs/5-1.txt") #+END_SRC

#+RESULTS: : 10766

** Part Two

#+BEGIN_SRC elisp (defun advent-of-code-2018-5-2-subr (unit input) (with-temp-buffer (insert input) (goto-char (point-min)) (let ((case-fold-search t)) (while (search-forward (string unit) nil t) (replace-match ""))) (goto-char (point-min)) (let (next) (while (setq next (char-after (1+ (point)))) (if (= (abs (- (char-after) next)) 32) (progn (delete-char 2) (goto-char (1- (point)))) (goto-char (1+ (point)))))) (buffer-size)))

(defun advent-of-code-2018-5-2 (input) (interactive (list (with-temp-buffer (insert-file-contents (read-file-name "Input file: ")) (string-trim-right (buffer-string))))) (message "%s" (cl-loop for unit from ?a to ?z minimize (advent-of-code-2018-5-2-subr unit input)))) #+END_SRC

#+RESULTS: : advent-of-code-2018-5-2

  • Day 6: Chronal Coordinates

** Part One

#+NAME: day6-tb1 | 1 | 1 | | 1 | 6 | | 8 | 3 | | 3 | 4 | | 5 | 5 | | 8 | 9 |

#+BEGIN_EXAMPLE aaaaa.cccc aAaaa.cccc aaaddecccc aadddeccCc ..dDdeeccc bb.deEeecc bBb.eeee.. bbb.eeefff bbb.eeffff bbb.ffffFf #+END_EXAMPLE

#+BEGIN_SRC elisp :var data=day6-tb1 :results pp (defun advent-of-code-2018-6-1-make-vector (data) (let (width height vv) (cl-loop initially (setq width 0 height 0) for (x y) in data do (setq width (max width x) height (max height y)) finally (cl-incf width) (cl-incf height)) (setq vv (make-vector height nil)) (cl-loop for v across-ref vv do (setf v (make-vector width -1))) vv))

(advent-of-code-2018-6-1-make-vector data) #+END_SRC

#+RESULTS: #+BEGIN_EXAMPLE [[-1 -1 -1 -1 -1 -1 -1 -1 -1] [-1 -1 -1 -1 -1 -1 -1 -1 -1] [-1 -1 -1 -1 -1 -1 -1 -1 -1] [-1 -1 -1 -1 -1 -1 -1 -1 -1] [-1 -1 -1 -1 -1 -1 -1 -1 -1] [-1 -1 -1 -1 -1 -1 -1 -1 -1] [-1 -1 -1 -1 -1 -1 -1 -1 -1] [-1 -1 -1 -1 -1 -1 -1 -1 -1] [-1 -1 -1 -1 -1 -1 -1 -1 -1] [-1 -1 -1 -1 -1 -1 -1 -1 -1]] #+END_EXAMPLE

#+BEGIN_SRC elisp (defun advent-of-code-2018-6-1-manhattan-distance (x1 y1 x2 y2) (+ (abs (- x1 x2)) (abs (- y1 y2)))) #+END_SRC

#+RESULTS: : advent-of-code-2018-6-1-manhattan-distance

#+BEGIN_SRC elisp :var data=day6-tb1 :results pp (defun advent-of-code-2018-6-1-fill-vector (vv data) (let ((height (length vv)) (width (length (elt vv 0)))) (dotimes (i height) (dotimes (j width) (let ((tmp (cl-loop for (x y) in data for index from 0 collect (cons index (+ (abs (- x j)) (abs (- y i)))) into result finally return (sort result (lambda (p1 p2) (< (cdr p1) (cdr p2))))))) (unless (= (cdr (elt tmp 0)) (cdr (elt tmp 1))) (setf (elt (elt vv i) j) (caar tmp)))))) vv))

(advent-of-code-2018-6-1-fill-vector (advent-of-code-2018-6-1-make-vector data) data) #+END_SRC

#+RESULTS: #+BEGIN_EXAMPLE [[0 0 0 0 0 -1 2 2 2] [0 0 0 0 0 -1 2 2 2] [0 0 0 3 3 4 2 2 2] [0 0 3 3 3 4 2 2 2] [-1 -1 3 3 3 4 4 2 2] [1 1 -1 3 4 4 4 4 2] [1 1 1 -1 4 4 4 4 -1] [1 1 1 -1 4 4 4 5 5] [1 1 1 -1 4 4 5 5 5] [1 1 1 -1 5 5 5 5 5]] #+END_EXAMPLE

#+BEGIN_SRC elisp :var data=day6-tb1 :results pp (defun advent-of-code-2018-6-1-find-infinite (vv) (let ((height (length vv)) (width (length (elt vv 0))) result) (dotimes (i height) (dotimes (j width) (when (or (= i 0) (= i (1- height)) (= j 0) (= j (1- width))) (push (elt (elt vv i) j) result)))) (delq -1 result)))

(advent-of-code-2018-6-1-find-infinite (advent-of-code-2018-6-1-fill-vector (advent-of-code-2018-6-1-make-vector data) data)) #+END_SRC

#+RESULTS: : (5 5 5 5 5 1 1 1 5 1 5 1 1 2 1 2 2 0 2 0 2 0 2 2 2 0 0 0 0 0)

#+BEGIN_SRC elisp :var data=day6-tb1 :results pp (defun advent-of-code-2018-6-1-find-finite (vv data) (cl-set-difference (number-sequence 0 (1- (length data))) (advent-of-code-2018-6-1-find-infinite vv)))

(advent-of-code-2018-6-1-find-finite (advent-of-code-2018-6-1-fill-vector (advent-of-code-2018-6-1-make-vector data) data) data) #+END_SRC

#+RESULTS: : (3 4)

#+BEGIN_SRC elisp :var data=day6-tb1 :results pp (defun advent-of-code-2018-6-1-area (vv x) (cl-loop for v across vv sum (cl-loop for i across v count (= x i))))

(advent-of-code-2018-6-1-area (advent-of-code-2018-6-1-fill-vector (advent-of-code-2018-6-1-make-vector data) data) 4) #+END_SRC

#+RESULTS: : 17

#+BEGIN_SRC elisp :var data=day6-tb1 :results pp (defun advent-of-code-2018-6-1-largest-area (data) (let ((vv (advent-of-code-2018-6-1-fill-vector (advent-of-code-2018-6-1-make-vector data) data))) (cl-loop for x in (advent-of-code-2018-6-1-find-finite vv data) maximize (advent-of-code-2018-6-1-area vv x))))

(advent-of-code-2018-6-1-largest-area data) #+END_SRC

#+RESULTS: : 17

#+BEGIN_SRC elisp (defun advent-of-code-2018-6-1-parse (file) (with-temp-buffer (insert-file-contents file) (cl-loop for (a b) on (split-string (buffer-string) (rx (or ", " "\n")) t) by #'cddr collect (list (read a) (read b)))))

(advent-of-code-2018-6-1-parse "inputs/6-1.txt") #+END_SRC

#+RESULTS: | 137 | 140 | | 318 | 75 | | 205 | 290 | | 104 | 141 | | 163 | 104 | | 169 | 164 | | 238 | 324 | | 180 | 166 | | 260 | 198 | | 189 | 139 | | 290 | 49 | | 51 | 350 | | 51 | 299 | | 73 | 324 | | 220 | 171 | | 146 | 336 | | 167 | 286 | | 51 | 254 | | 40 | 135 | | 103 | 138 | | 100 | 271 | | 104 | 328 | | 80 | 67 | | 199 | 180 | | 320 | 262 | | 215 | 290 | | 96 | 142 | | 314 | 128 | | 162 | 106 | | 214 | 326 | | 303 | 267 | | 340 | 96 | | 211 | 278 | | 335 | 250 | | 41 | 194 | | 229 | 291 | | 45 | 97 | | 304 | 208 | | 198 | 214 | | 250 | 80 | | 200 | 51 | | 287 | 50 | | 120 | 234 | | 106 | 311 | | 41 | 116 | | 359 | 152 | | 189 | 207 | | 300 | 167 | | 318 | 315 | | 296 | 72 |

#+BEGIN_SRC elisp (advent-of-code-2018-6-1-largest-area (advent-of-code-2018-6-1-parse "inputs/6-1.txt")) #+END_SRC

#+RESULTS: : 4398

** Part Two

#+BEGIN_SRC elisp :var data=day6-tb1 :results pp (defun advent-of-code-2018-6-2-region-size (data limit) (let* ((vv (advent-of-code-2018-6-1-make-vector data)) (width (length (elt vv 0))) (height (length vv))) (cl-loop for y below height sum (cl-loop for x below width count (cl-loop for (x1 y1) in data sum (+ (abs (- x x1)) (abs (- y y1))) into tmp finally return (< tmp limit))))))

;; Otherwise it will be very slow (byte-compile 'advent-of-code-2018-6-2-region-size) (advent-of-code-2018-6-2-region-size data 32) #+END_SRC

#+RESULTS: : 16

#+BEGIN_SRC elisp (advent-of-code-2018-6-2-region-size (advent-of-code-2018-6-1-parse "inputs/6-1.txt") 10000) #+END_SRC

#+RESULTS: : 39560