(in-package :aoc/2024) (defparameter *input/d1* (asdf:system-relative-pathname :advent "2024/d01.input")) (defun readlists (filename) "Read the left and right columns of numbers into individual lists" (let ((left-numbers '()) (right-numbers '())) (with-open-file (stream filename :direction :input) (loop for line = (read-line stream nil nil) while line do (let* ((tab-pos (search " " line)) (left (parse-integer (subseq line 0 tab-pos))) (right (parse-integer (subseq line (1+ tab-pos))))) (push left left-numbers) (push right right-numbers)))) (list (nreverse left-numbers) (nreverse right-numbers)))) (let* ((input-list (readlists *input/d1*)) (left (sort (first input-list) #'<)) (right (sort (second input-list) #'<)) (diff (mapcar #'- left right)) (absdiff (mapcar #'abs diff)) (result (apply #'+ absdiff))) (print result)) ; 2066446 (let* ((input-list (readlists *input/d1*)) (left (first input-list)) (right (second input-list)) (result (apply #'+ (mapcar #'(lambda (x) (* x (count x right))) left)))) (print result)) ; 24931009