aboutsummaryrefslogtreecommitdiff
path: root/2019/05/puzzles.lisp
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-12-18 13:10:22 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-12-18 13:10:22 +0100
commit57035d465f81d2e1a57292d92276f863ff88af9a (patch)
tree6279b41bc68de7d906fc346bda63b968a6a63cdc /2019/05/puzzles.lisp
parente951c0de29a08976e3fdb14fa074bd5999555fb5 (diff)
Make changes to the interpreter
Diffstat (limited to '2019/05/puzzles.lisp')
-rw-r--r--2019/05/puzzles.lisp25
1 files changed, 18 insertions, 7 deletions
diff --git a/2019/05/puzzles.lisp b/2019/05/puzzles.lisp
index 1d42479..c358e5a 100644
--- a/2019/05/puzzles.lisp
+++ b/2019/05/puzzles.lisp
@@ -2,10 +2,21 @@
(load "../interpreter.lisp")
-(format t "~d~%" (car (last (intcode:run (intcode:parse "input")
- ;; START PART 1
- '(1)
- ;; END PART 1 START PART 2
- '(5)
- ;; END PART 2
- )))) \ No newline at end of file
+(defun main (filename)
+ (let ((stdin (make-string-input-stream
+ ;; START PART 1
+ "1"
+ ;; END PART 1 START PART 2
+ "5"
+ ;; END PART 2
+ ))
+ (stdout (make-string-output-stream)))
+ (intcode:run (intcode:parse "input") stdin stdout)
+ (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)))
+
+(format t "~d~%" (main "input")) \ No newline at end of file