day 1 part 1

This commit is contained in:
Alan Daniels 2025-12-02 18:24:57 +11:00
commit 920f9032dd
4 changed files with 66 additions and 0 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

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*data.txt

45
01a.lisp Normal file
View file

@ -0,0 +1,45 @@
(require :uiop)
(defun split-instruction (s)
(cons
(intern (subseq s 0 1))
(parse-integer (subseq s 1))))
(defun turn-dial (dial instruction)
(let ((cons-instruction (split-instruction instruction)))
(let ((op (car cons-instruction))
(amount (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")
;; (turn-dial 0 "L5")
;; (turn-dial 95 "R60")
;; (turn-dial 55 "L55")
;; (turn-dial 0 "L1")
;; (turn-dial 99 "L99")
;; (turn-dial 0 "R14")
;; (turn-dial 14 "L82")
(defun rec-dial-vm (accum dial lines)
(let ((instruction (pop lines)))
(if instruction
(let ((new-dial (turn-dial dial instruction)))
;(format t "~A ~A -> ~A ~%" dial instruction new-dial)
(if (= new-dial 0)
(rec-dial-vm (+ 1 accum) new-dial lines)
(rec-dial-vm 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"))

10
01example.txt Normal file
View file

@ -0,0 +1,10 @@
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82