formatting

This commit is contained in:
Alan Daniels 2025-12-02 18:31:49 +11:00
parent af70982d4b
commit 596e98d951
2 changed files with 28 additions and 18 deletions

10
.editorconfig Normal file
View file

@ -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

View file

@ -1,24 +1,24 @@
(require :uiop) (require :uiop)
(defun split-instruction (s) (defun split-instruction (s)
"Splits a string S into two parts at the given INDEX." "Splits the given instruction into a pair"
(cons (subseq s 0 1) (cons (subseq s 0 1)
(subseq s 1))) (subseq s 1)))
(defun turn-dial (dial instruction) (defun turn-dial (dial instruction)
(let ((cons-instruction (split-instruction instruction))) (let ((cons-instruction (split-instruction instruction)))
(let ((op (intern (car cons-instruction))) (let ((op (intern (car cons-instruction)))
(amount (parse-integer (cdr cons-instruction)))) (amount (parse-integer (cdr cons-instruction))))
(mod (mod
(funcall (funcall
(cond (cond
((eql 'L op) #'-) ((eql 'L op) #'-)
((eql 'R op) #'+) ((eql 'R op) #'+)
(t (error "unknown op"))) (t (error "unknown op")))
dial amount) dial amount)
100) 100)
) )
)) ))
;; (turn-dial 50 "L68") ;; (turn-dial 50 "L68")
;; (turn-dial 82 "L30") ;; (turn-dial 82 "L30")
@ -27,10 +27,10 @@
(defun rec-dial-vm (accum dial lines) (defun rec-dial-vm (accum dial lines)
(let ((instruction (pop lines))) (let ((instruction (pop lines)))
(if instruction (if instruction
(let ((new-dial (turn-dial dial instruction))) (let ((new-dial (turn-dial dial instruction)))
(if (= new-dial 0) (if (= new-dial 0)
(rec-dial-vm accum new-dial lines) (rec-dial-vm accum new-dial lines)
(rec-dial-vm (+ 1 accum) new-dial lines))) (rec-dial-vm (+ 1 accum) new-dial lines)))
accum))) accum)))
(rec-dial-vm 0 50 (uiop:read-file-lines "01example.txt")) (rec-dial-vm 0 50 (uiop:read-file-lines "01example.txt"))