diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-12-14 22:46:34 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-12-14 22:46:34 +0100 |
commit | df25235f1e020f943397a28d6a87c6d84b542c17 (patch) | |
tree | de319e96404d89b3ebc311ae650fd5e24866f7b4 /2019/02/puzzles.lisp | |
parent | 2f97464bff64652faa8038e392ced279e03dd607 (diff) |
Add 2019 day 2 solutions
Diffstat (limited to '2019/02/puzzles.lisp')
-rw-r--r-- | 2019/02/puzzles.lisp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/2019/02/puzzles.lisp b/2019/02/puzzles.lisp new file mode 100644 index 0000000..9a3acb7 --- /dev/null +++ b/2019/02/puzzles.lisp @@ -0,0 +1,24 @@ +#!/usr/bin/sbcl --script + +(load "../interpreter.lisp") + +(defun run-with-noun-and-verb (noun verb ram) + (setf (aref ram 1) noun + (aref ram 2) verb) + (intcode:run ram) + (aref ram 0)) + +;; START PART 1 +(let ((program (intcode:parse "input"))) + (format t "~d~%" (run-with-noun-and-verb 12 2 program))) +;; END PART 1 START PART 2 +(let* ((program (intcode:parse "input")) + (ram (make-array (length program)))) + (dotimes (noun 100) + (dotimes (verb 100) + (loop for i from 0 below (length program) + do (setf (aref ram i) (aref program i))) + (when (= (run-with-noun-and-verb noun verb ram) 19690720) + (format t "~d~%" (+ (* 100 noun) verb)) + (quit))))) +;; END PART 2
\ No newline at end of file |