src/2019/days/day-11.lisp @ 0b68f84e44ae
2021/08 and 2020/13/1
| author | Steve Losh <steve@stevelosh.com> |
|---|---|
| date | Wed, 08 Dec 2021 18:00:32 -0800 |
| parents | 182bdd87fd9e |
| children | (none) |
(advent:defpackage* :advent/2019/11) (in-package :advent/2019/11) (defun run-robot (program &key (origin 'black)) (let ((panels (make-hash-table)) (mode '#1=(paint walk . #1#)) (pos #c(0 0)) (heading #c(0 1))) (labels ((color () (gethash pos panels 0)) (paint (color) (setf (gethash pos panels) color)) (turn (direction) (mulf heading (ecase direction (0 #c(0 1)) (1 #c(0 -1))))) (walk (direction) (turn direction) (incf pos heading)) (exec (input) (ecase (pop mode) (paint (paint input)) (walk (walk input))))) (paint (ecase origin (black 0) (white 1))) (advent/intcode:run program :input #'color :output #'exec)) panels)) (defun draw-panels (panels) (draw-bitmap (alexandria:hash-table-alist panels) "out/2019-11.pbm" :flip-vertically t)) (define-problem (2019 11) (data read-numbers) (1907) (draw-panels (run-robot data :origin 'white)) (hash-table-count (run-robot data))) #; Scratch --------------------------------------------------------------------