From 14f9c394cc233bdcda23e601a210082701e8d606 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 17 Dec 2024 21:53:08 +0100 Subject: Add 2024 day 17 solutions --- 2024/17/puzzle-1.lisp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 2024/17/puzzle-1.lisp (limited to '2024/17/puzzle-1.lisp') 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 -- cgit v1.2.3