(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)))