14 lines
470 B
Common Lisp
14 lines
470 B
Common Lisp
(defun calories-per-elf (input)
|
|
(mapcar (lambda (x) (cl-ppcre:split "\\s+" x))
|
|
(cl-ppcre:split "\\n\\n" (uiop:read-file-string input))))
|
|
|
|
(defun parse-strings-and-sum (cals-per-elf)
|
|
(reduce '+ (mapcar #'parse-integer cals-per-elf)))
|
|
|
|
(defun part-one (input)
|
|
(apply #'max (mapcar #'parse-strings-and-sum
|
|
(calories-per-elf input))))
|
|
|
|
(defun part-two (input)
|
|
(reduce '+ (subseq (sort (mapcar #'parse-strings-and-sum (calories-per-elf input)) '>) 0 3)))
|