diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-12-18 18:58:32 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-12-18 18:58:32 +0100 |
commit | aeeb7856d32a904d22c5f1cdeca443bb7fcd7e49 (patch) | |
tree | 4aacd9f841f515254ed581970070b3e1aa72301f /2019/05 | |
parent | 65beb3ea0223e693ac348c6133e496ada2b2352f (diff) |
Refactor the intcode machine
Diffstat (limited to '2019/05')
-rw-r--r-- | 2019/05/puzzles.lisp | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/2019/05/puzzles.lisp b/2019/05/puzzles.lisp index 28eb32d..7602231 100644 --- a/2019/05/puzzles.lisp +++ b/2019/05/puzzles.lisp @@ -3,19 +3,10 @@ (load "../interpreter.lisp") (defun main (filename) - (let ((stdout (make-string-output-stream))) - (intcode:run (intcode:parse "input") nil stdout :initial-arguments - ;; START PART 1 - '(1) - ;; END PART 1 START PART 2 - '(5) - ;; END PART 2 - ) - (parse-integer (last-line (get-output-stream-string stdout))))) - -(defun last-line (string) - (let* ((nl-e (position #\Newline string :from-end t)) - (nl-b (position #\Newline string :from-end t :end nl-e))) - (subseq string (1+ (or nl-b -1)) nl-e))) + (let (result) + (intcode:run (intcode:parse filename) + (lambda () (if (= +puzzle-part+ 1) 1 5)) + (lambda (x) (setq result x))) + result)) (format t "~d~%" (main "input"))
\ No newline at end of file |