diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-12-18 20:37:45 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-12-18 20:37:45 +0100 |
commit | 35e57f6e59423272fd4a45b2535c369cb61182b5 (patch) | |
tree | fb67212bc14a1abc0bb53eac10fbd8e0b9a598cf | |
parent | 3e4fca1014d8b27d1a852f74e998d9f1d35930f4 (diff) |
Add 2019 day 13 solutions
-rwxr-xr-x | 2019/13/puzzle-1.lisp | 19 | ||||
-rwxr-xr-x | 2019/13/puzzle-2.lisp | 33 |
2 files changed, 52 insertions, 0 deletions
diff --git a/2019/13/puzzle-1.lisp b/2019/13/puzzle-1.lisp new file mode 100755 index 0000000..aeda572 --- /dev/null +++ b/2019/13/puzzle-1.lisp @@ -0,0 +1,19 @@ +#!/usr/bin/sbcl --script + +(load "../interpreter.lisp") + +(defun main (filename) + (let ((blocks (make-hash-table)) + parts) + (intcode:run (intcode:parse "input") nil + (lambda (msg) + (if (< (length parts) 2) + (push msg parts) + (let ((y (first parts)) + (x (second parts))) + (when (= msg 2) + (setf (gethash (complex x y) blocks) t)) + (setq parts nil))))) + (hash-table-count blocks))) + +(format t "~d~%" (main "input"))
\ No newline at end of file diff --git a/2019/13/puzzle-2.lisp b/2019/13/puzzle-2.lisp new file mode 100755 index 0000000..66dd33d --- /dev/null +++ b/2019/13/puzzle-2.lisp @@ -0,0 +1,33 @@ +#!/usr/bin/sbcl --script + +(load "../interpreter.lisp") + +(defun sign (x) + (cond ((minusp x) -1) + ((plusp x) +1) + (:else 0))) + +(defun main (filename) + (let ((program (intcode:parse filename)) + (part 0) score + ball-x paddle-x + msg-x msg-y msg-z) + (setf (aref program 0) 2) + (intcode:run + program + (lambda () + (sign (- ball-x paddle-x))) + (lambda (msg) + (ecase part + (0 (setq msg-x msg)) + (1 (setq msg-y msg)) + (2 (case msg + (3 (setq paddle-x msg-x)) + (4 (setq ball-x msg-x)) + (otherwise + (when (and (= msg-x -1) (= msg-y 0)) + (setq score msg)))))) + (setq part (mod (1+ part) 3)))) + score)) + +(format t "~d~%" (main "input"))
\ No newline at end of file |