diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-11-06 09:58:38 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-11-06 09:58:38 -0800 |
commit | 4fd1aae518076adc8b97735225c678d6a362328d (patch) | |
tree | 97d61b659fc3cac628d0cdee71128a0baee2cb73 /2021/17/code.tl | |
download | advent-4fd1aae518076adc8b97735225c678d6a362328d.tar.gz advent-4fd1aae518076adc8b97735225c678d6a362328d.tar.bz2 advent-4fd1aae518076adc8b97735225c678d6a362328d.zip |
Kazinator's Advent of Code stuff.
Diffstat (limited to '2021/17/code.tl')
-rw-r--r-- | 2021/17/code.tl | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/2021/17/code.tl b/2021/17/code.tl new file mode 100644 index 0000000..af76de0 --- /dev/null +++ b/2021/17/code.tl @@ -0,0 +1,46 @@ +(defstruct spec () + x0 x1 + y0 y1) + +(defun read-input (: (name "input")) + (flow name + file-get-string + (match `target area: x=@x0..@x1, y=@y0..@y1\n@nil` @1 + (new spec x0 (toint x0) x1 (toint x1) y0 (toint y0) y1 (toint y1))))) + +(defun simulate-shot (sp xv yv) + (let ((x0 sp.x0) (x1 sp.x1) + (y0 sp.y0) (y1 sp.y1)) + (for ((x 0) (y 0) (maxy -1000)) () () + (cond + ((or (< y y0) (> x x1)) + (return)) + ((and (<= x0 x x1) (<= y0 y y1)) + (return maxy))) + (inc x xv) + (inc y yv) + (upd maxy (max y maxy)) + (dec xv (signum xv)) + (dec yv 1)))) + +(defun solve-one (: (name :)) + (let ((sp (read-input name))) + (flow + (build + (each-prod ((xv 1..40) + (yv 1..700)) + (iflet ((maxy (simulate-shot sp xv yv))) + (add (list xv yv maxy))))) + (find-max @1 : caddr)))) + +(defun solve-two (: (name :)) + (let ((sp (read-input name))) + (flow + (build + (each-prod ((xv 1..300) + (yv -100..400)) + (iflet ((maxy (simulate-shot sp xv yv))) + (add (list xv yv maxy))))) + (mapcar (ap list @1 @2)) + uniq + len))) |