commit 6513fd0b73342766cf82f9ad98942928cee08fbc parent bded8d6fde3bd769f32fd0c87ac40bee593b3477 Author: Martin Ashby <martin@ashbysoft.com> Date: Wed, 10 Dec 2025 21:50:20 +0000 Day 1 part 2 Diffstat:
| M | 01.lisp | | | 21 | ++++++++++++++++++--- |
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/01.lisp b/01.lisp @@ -1,4 +1,4 @@ -(defun day1 (input-file) +(defun day1-part1 (input-file) (with-open-file (s input-file) (let ((dial 50) (zeroes 0)) @@ -9,4 +9,19 @@ (op (if is-r #'+ #'-))) (setf dial (mod (funcall op dial n) 100)) (if (equal 0 dial) - (setf zeroes (1+ zeroes)))))))) -\ No newline at end of file + (setf zeroes (1+ zeroes)))))))) + +; We'll go for a naive approach early in the game, just count in steps of one and check the zeroes. +(defun day1-part2 (input-file) + (with-open-file (s input-file) + (let ((dial 50) + (zeroes 0)) + (do ((line (read-line s nil) (read-line s nil))) + ((equal line nil) zeroes) + (let* ((n (parse-integer (subseq line 1))) + (is-r (equal "R" (subseq line 0 1))) + (op (if is-r #'+ #'-))) + (dotimes (i n) + (setf dial (mod (funcall op dial 1) 100)) + (if (equal 0 dial) + (setf zeroes (1+ zeroes))))))))) +\ No newline at end of file