From f23b57487eeb3d280c1f5341cfe95af6e4b4a029 Mon Sep 17 00:00:00 2001 From: "(Bit-Mage)" Date: Tue, 3 Dec 2024 11:43:18 +0530 Subject: [PATCH] updates Signed-off-by: (Bit-Mage) --- .../20241202121706-advent_of_code_2024.org | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/Content/20241202121706-advent_of_code_2024.org b/Content/20241202121706-advent_of_code_2024.org index 906a457..d96ad79 100644 --- a/Content/20241202121706-advent_of_code_2024.org +++ b/Content/20241202121706-advent_of_code_2024.org @@ -4,8 +4,46 @@ #+title: Advent of Code 2024 #+filetags: :project: -I'm prepping input via vim macros - +* Day 3 +#+begin_src lisp +(ql:quickload :uiop) +(ql:quickload :cl-ppcre) + +(defvar input (read-file-to-string "input")) + +;; part 1 + +(defun extract-mul-parameters (input-string) + (multiple-value-bind (matched-p matches) + (cl-ppcre:scan-to-strings "mul\\((\\d+),(\\d+)\\)" input-string) + (when matched-p + matches))) + +(defun parse-mul (match) + (let* ((parse-vec (extract-mul-parameters match)) + (n1 (parse-integer (svref parse-vec 0))) + (n2 (parse-integer (svref parse-vec 1)))) + (* n1 n2))) + +(defun solve-p1 (input) + (apply #'+ (mapcar #'parse-mul + (cl-ppcre:all-matches-as-strings + "mul\\((\\d+),(\\d+)\\)" + input)))) +;; part 2 + +(defun solve-p2 (input) + (let ((do? t) + (acc 0)) + (dolist (state (cl-ppcre:all-matches-as-strings + "mul\\((\\d+),(\\d+)\\)|do\\(\\)|don't\\(\\)" + input) + acc) + (cond ((equal state "do()") (setf do? t)) + ((equal state "don't()") (setf do? nil)) + (t (when do? + (incf acc (parse-mul state)))))))) +#+end_src * Day 2 #+begin_src lisp