-
Notifications
You must be signed in to change notification settings - Fork 0
/
day19.lisp
33 lines (28 loc) · 930 Bytes
/
day19.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
;;;; day19.lisp
(in-package :aoc2019.day19)
(defvar *code*)
(defun position-affected-p (x y)
(= 1
(first (prog-outputs (execute-program! (load-program
*code*
:inputs (list x y)))))))
(defun day19 ()
(let ((*code* (first (read-puzzlefile 19))))
(loop
:for x :from 0 :below 50
:sum (loop
:for y :from 0 :below 50
:counting (position-affected-p x y)))))
(defun find-affected-start (y &optional (start-x 0))
(loop
:for x :from start-x
:until (position-affected-p x y)
:finally (return x)))
(defun day19-part2 (&optional (size 100))
(let ((*code* (first (read-puzzlefile 19))))
(loop
:with edge-length := (- size 1)
:for y :from size
:for x := (find-affected-start y) :then (find-affected-start y x)
:until (position-affected-p (+ x edge-length) (- y edge-length))
:finally (return (+ (- y edge-length) (* 10000 x))))))