src/2019/days/day-11.lisp @ 2848a4548adf
2023/01 and 2022/01
Also start porting my test data to the new account, since Twitter imploded and
apparently it's impossible for a website to store a goddamn username and
password in The Year of Our Lord 2023 so everyone just outsources auth all
the time, ugh.
author |
Steve Losh <steve@stevelosh.com> |
date |
Fri, 01 Dec 2023 11:05:43 -0500 |
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 --------------------------------------------------------------------