Files
advent-of-code/2025/puzzle-1.lisp
Aryadev Chavali 55a352a08e aoc 2025 - still need to 7
Forgot to push these all onto the cloud lol
2025-12-07 07:52:17 +00:00

41 lines
1.4 KiB
Common Lisp

(load "util.lisp")
(defpackage "aoc:1"
(:use :cl "aoc-util"))
(in-package "aoc:1")
(fn round-1 (turns) (=> list fixnum)
(loop with dial = 50
with number-of-zeros = 0
for (rotation . magnitude) in turns
do (setf dial (mod (funcall rotation dial magnitude) 100))
if (= dial 0)
do (incf number-of-zeros)
finally (return number-of-zeros)))
(fn round-2 (turns) (=> list fixnum)
(loop with dial = 50
with number-of-zeros = 0
for (rotation . magnitude) in turns
;; FUCK I have to do this manually, too many edge cases
do (loop for i from 1 to magnitude
for new-dial-value = (funcall rotation dial 1)
if (or (= new-dial-value 0) (= new-dial-value 100))
do (incf number-of-zeros)
do (setf dial (mod new-dial-value 100)))
finally (return number-of-zeros)))
(let ((turns (loop for line in (uiop:read-file-lines "1-input")
for (rotation magnitude) = (->> line (split 1) multiple-value-list)
collect (cons (if (string= rotation "L")
#'-
#'+)
(parse-integer* magnitude)))))
(->> turns
round-1
(format t "Round 1: ~a~%"))
(->> turns
round-2
(format t "Round 2: ~a~%")))