diff options
| author | Syndamia <kamen@syndamia.com> | 2022-12-02 12:10:03 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2022-12-02 12:10:03 +0200 |
| commit | 15aab5d23ae97f4dd498bf3460be1ef22e31f3b5 (patch) | |
| tree | c34cc19177f08a72c513af478c33894bceb1f9da /2022/Day01/part-two.cl | |
| parent | c8f083a44f655b00c2aa229cff25a7aef2432699 (diff) | |
| download | advent-of-code-15aab5d23ae97f4dd498bf3460be1ef22e31f3b5.tar advent-of-code-15aab5d23ae97f4dd498bf3460be1ef22e31f3b5.tar.gz advent-of-code-15aab5d23ae97f4dd498bf3460be1ef22e31f3b5.zip | |
[2022] Updated names of folders
Diffstat (limited to '2022/Day01/part-two.cl')
| -rw-r--r-- | 2022/Day01/part-two.cl | 21 |
1 files changed, 21 insertions, 0 deletions
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*)) |
