aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/01/solver.lisp
blob: d39bb7ce1259afa493b322b9d55ec1d431050c24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
; run sbcl --load ~/.sbclrc --script solver.lisp

(ql:quickload '(:uiop :fiveam))

(defun elves-rations ()
    (reduce
     (lambda (acc value)
       (if (string= value "")
           (cons 0 acc)
           (progn
             (incf (car acc) (parse-integer value))
             acc)))
     (uiop:read-file-lines "input")
     :initial-value (list 0)))

(fiveam:test results
  (let ((rations (elves-rations)))
    ;; calculate the maximum from each elves rations
    (fiveam:is (= 75622 (apply #'max rations)))
    ;; calculate the maximum from each elves rations
    (fiveam:is (= 213159 (apply #'+ (subseq (sort rations #'>) 0 3))))))