diff options
Diffstat (limited to '2024/17/puzzle-1.lisp')
-rwxr-xr-x | 2024/17/puzzle-1.lisp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/2024/17/puzzle-1.lisp b/2024/17/puzzle-1.lisp new file mode 100755 index 0000000..175c9f1 --- /dev/null +++ b/2024/17/puzzle-1.lisp @@ -0,0 +1,34 @@ +#!/usr/bin/sbcl --script + +(load "machine.lisp") + +(defun main (filename) + (multiple-value-call #'machine:run (parse filename))) + +(defun parse (filename) + (with-open-file (stream filename) + (let ((contents (make-string (file-length stream)))) + (read-sequence contents stream) + (extract-numbers-from-string contents)))) + +(defun extract-numbers-from-string (string) + (let (numbers) + (loop do + (let* ((beg (position-if #'digit-char-p string)) + (end (position-if-not #'digit-char-p string :start (or beg 0)))) + (unless beg + (loop-finish)) + (push (parse-integer (subseq string beg end)) numbers) + (setq string (subseq string (or end (length string)))))) + (setq numbers (nreverse numbers)) + (values + (coerce (cdddr numbers) 'vector) + (first numbers) + (second numbers) + (third numbers)))) + +(loop with output = (main "input") + for number in output + for i upfrom 1 + do (format t "~d~c" number (if (= i (length output)) + #\Newline #\,)))
\ No newline at end of file |