Belated 2024 first puzzle solution
This commit is contained in:
15
2024/puzzle-1.lisp
Normal file
15
2024/puzzle-1.lisp
Normal file
@@ -0,0 +1,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))))
|
||||
11
2024/util.lisp
Normal file
11
2024/util.lisp
Normal file
@@ -0,0 +1,11 @@
|
||||
(defmacro --> (first &rest functions)
|
||||
(if (null functions)
|
||||
first
|
||||
`(let* ,(loop :for f :in (cons first functions)
|
||||
appending `((_ ,f)))
|
||||
_)))
|
||||
|
||||
(defun zip (a b)
|
||||
(loop for i in a
|
||||
for j in b
|
||||
collect (cons i j)))
|
||||
Reference in New Issue
Block a user