From a5681362f4f78478b528c6d888855d7a6bfb46a1 Mon Sep 17 00:00:00 2001 From: Alan Daniels Date: Tue, 2 Dec 2025 18:24:57 +1100 Subject: [PATCH] day 1 part 1 formatting --- .editorconfig | 10 ++++++++++ .gitignore | 1 + 01a.lisp | 37 +++++++++++++++++++++++++++++++++++++ 01example.txt | 10 ++++++++++ 4 files changed, 58 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 01a.lisp create mode 100644 01example.txt diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0f09989 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d01eb1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*data.txt diff --git a/01a.lisp b/01a.lisp new file mode 100644 index 0000000..ec0d754 --- /dev/null +++ b/01a.lisp @@ -0,0 +1,37 @@ +(require :uiop) + +(defun split-instruction (s) + "Splits the given instruction into a pair" + (cons (subseq s 0 1) + (subseq s 1))) + +(defun turn-dial (dial instruction) + (let ((cons-instruction (split-instruction instruction))) + (let ((op (intern (car cons-instruction))) + (amount (parse-integer (cdr cons-instruction)))) + (mod + (funcall + (cond + ((eql 'L op) #'-) + ((eql 'R op) #'+) + (t (error "unknown op"))) + dial amount) + 100) + ) + )) + +;; (turn-dial 50 "L68") +;; (turn-dial 82 "L30") +;; (turn-dial 52 "R48") + +(defun rec-dial-vm (accum dial lines) + (let ((instruction (pop lines))) + (if instruction + (let ((new-dial (turn-dial dial instruction))) + (if (= new-dial 0) + (rec-dial-vm accum new-dial lines) + (rec-dial-vm (+ 1 accum) new-dial lines))) + accum))) + +(rec-dial-vm 0 50 (uiop:read-file-lines "01example.txt")) +(rec-dial-vm 0 50 (uiop:read-file-lines "01data.txt")) diff --git a/01example.txt b/01example.txt new file mode 100644 index 0000000..53287c7 --- /dev/null +++ b/01example.txt @@ -0,0 +1,10 @@ +L68 +L30 +R48 +L5 +R60 +L55 +L1 +L99 +R14 +L82