aboutsummaryrefslogtreecommitdiff
path: root/2024/puzzle-1.lisp
blob: ad667d41ea397a4c5aac37a4988884ea22ef4861 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(load "util.lisp")

(--> (uiop:read-file-lines "1-input")
     (loop for line in _
           for x = (search "   " line)
           collect (parse-integer (subseq line 0 x)) into left
           collect (parse-integer (subseq line (+ x 3))) into right
           finally (return (list (sort left #'<) (sort right #'<))))
     (format t "Round 1: ~a~%Round 2: ~a~%"
             (loop for x in (car _)
                   for y in (cadr _)
                   sum (abs (- y x)))
             (loop for item in (car _)
                   for count = (count item (cadr _))
                   sum (* item count))))