diff options
Diffstat (limited to '2022/Day1/part-two.cl')
| -rw-r--r-- | 2022/Day1/part-two.cl | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/2022/Day1/part-two.cl b/2022/Day1/part-two.cl new file mode 100644 index 0000000..2d88791 --- /dev/null +++ b/2022/Day1/part-two.cl @@ -0,0 +1,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*)) |
