diff options
author | Oscar Najera <hi@oscarnajera.com> | 2022-12-02 14:54:40 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2022-12-02 15:15:21 +0100 |
commit | ad4be3275a5fa46725292cfeee72fad6835159f4 (patch) | |
tree | 29f937f01e82850b66e080440642841f44dac61d /AoC2022/01/solver.lisp | |
parent | c961041fb211c4e72f306a113ef2bb4b8385be1d (diff) | |
download | scratch-ad4be3275a5fa46725292cfeee72fad6835159f4.tar.gz scratch-ad4be3275a5fa46725292cfeee72fad6835159f4.tar.bz2 scratch-ad4be3275a5fa46725292cfeee72fad6835159f4.zip |
[AoC2022] Common lisp and makefile runner
Diffstat (limited to 'AoC2022/01/solver.lisp')
-rwxr-xr-x | AoC2022/01/solver.lisp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/AoC2022/01/solver.lisp b/AoC2022/01/solver.lisp new file mode 100755 index 0000000..ee84450 --- /dev/null +++ b/AoC2022/01/solver.lisp @@ -0,0 +1,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)))))) + +(fiveam:run-all-tests) |