From 15aab5d23ae97f4dd498bf3460be1ef22e31f3b5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 2 Dec 2022 12:10:03 +0200 Subject: [2022] Updated names of folders --- 2022/Day01/part-two.cl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 2022/Day01/part-two.cl (limited to '2022/Day01/part-two.cl') diff --git a/2022/Day01/part-two.cl b/2022/Day01/part-two.cl new file mode 100644 index 0000000..2d88791 --- /dev/null +++ b/2022/Day01/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*)) -- cgit v1.2.3