aboutsummaryrefslogtreecommitdiff
path: root/2022/Day01/part-two.cl
blob: 2d887917abf6de1908768846fcab597bce7c9fc3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(defvar *prog-input*)

(let ((ui (read-line)))
  (if (equal ui "")
    (setq *prog-input* *standard-input*)
    (setq *prog-input* (open ui))))

(let
  ((cal (read-line *prog-input* NIL)) (sums '(0)))

  (loop until (or (equal cal "end") (not cal)) do
    (if (equal cal "")
      (push 0 sums)
      (push (+ (pop sums) (parse-integer cal)) sums))
    (setq cal (read-line *prog-input* NIL)))

  (setq sums (sort sums #'>))
  (print (+ (first sums) (second sums) (third sums))))

(if (not (eq *prog-input* *standard-input*))
  (close *prog-input*))