diff --git a/2024/day-01/stage-2.lisp b/2024/day-01/stage-2.lisp new file mode 100644 index 0000000..1f1d345 --- /dev/null +++ b/2024/day-01/stage-2.lisp @@ -0,0 +1,25 @@ +(require 'asdf) + +(asdf:load-system "cl-strings") + +(require :cl-strings) + +(defun diff (data) + (let* ((lists (reduce (lambda (acc itm) (cons (cons (parse-integer (car itm)) (car acc)) (cons (parse-integer (cadr itm)) (cdr acc)))) + (mapcar (lambda (line) (cl-strings:split line " ")) + (cl-strings:split data " +")) + :initial-value (cons (list) (list))))) + (reduce (lambda (acc itm) + (+ acc (* (car itm) (cdr itm)))) + (mapcar (lambda (itm) (cons itm (count itm (cdr lists)))) (car lists)) + :initial-value 0))) + +(format t "~s~%" (diff "3 4 +4 3 +2 5 +1 3 +3 9 +3 3")) + +(format t "~s~%" (diff (string-right-trim '(#\Space #\Newline) (uiop:read-file-string "input"))))