aboutsummaryrefslogtreecommitdiff
path: root/2024/17/puzzle-1.lisp
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-12-17 21:53:08 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-12-17 21:53:08 +0100
commit14f9c394cc233bdcda23e601a210082701e8d606 (patch)
tree22d96addd61e091fb02ea62773d946211dfdda4f /2024/17/puzzle-1.lisp
parent3e50d2999949f4c7fa807fe289fb0b0d1a0a4512 (diff)
Add 2024 day 17 solutions
Diffstat (limited to '2024/17/puzzle-1.lisp')
-rwxr-xr-x2024/17/puzzle-1.lisp34
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