(defpackage #:advent.2024.01 (:use #:cl)) (in-package #:advent.2024.01) ;;; Part 1 ;; What is the total difference between your lists? (defun read-input (file) "Read an input FILE that's 2 columns of numbers. Return each column separately." (loop for line in (uiop:read-file-lines file) for (a b) = (ppcre:split "\\s+" line) collect a into list-a collect b into list-b finally (return (values (mapcar #'serapeum:parse-number list-a) (mapcar #'serapeum:parse-number list-b))))) (defvar *input* "01.input") (defun total-distance () (multiple-value-bind (left right) (read-input *input*) (apply #'+ (mapcar (lambda (a b) (abs (- a b))) (sort left #'<) (sort right #'<))))) ;;; Part 2 (defun similarity-score () (multiple-value-bind (left right) (read-input *input*) (loop for n in left sum (* n (loop for m in right count (= n m))))))