2024 day 3

This commit is contained in:
eriedaberrie 2024-12-02 21:50:19 -08:00
parent a7dc708a65
commit d2892f1a3b

28
2024/3/main.lisp Normal file
View file

@ -0,0 +1,28 @@
(asdf:load-system :cl-ppcre)
(defun solve-1 (line)
(let ((result 0))
(ppcre:do-register-groups (a b)
("mul\\(([0-9]+),([0-9]+)\\)" line result)
(incf result (* (parse-integer a) (parse-integer b))))))
(defun solve-2 (line)
(let ((result 0)
(enabled t))
(ppcre:do-register-groups (mul a b dop dontp)
("(mul\\(([0-9]+),([0-9]+)\\))|(do\\(\\))|(don't\\(\\))" line result)
(declare (ignore mul))
(cond
(dop
(setf enabled t))
(dontp
(setf enabled nil))
(enabled
(incf result (* (parse-integer a) (parse-integer b))))))))
(defun main ()
(let ((input (uiop:read-file-string "data.txt")))
(format t
"1: ~A~%2: ~A~%"
(solve-1 input)
(solve-2 input))))