From ad4be3275a5fa46725292cfeee72fad6835159f4 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Fri, 2 Dec 2022 14:54:40 +0100 Subject: [AoC2022] Common lisp and makefile runner --- AoC2022/01/solver.lisp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 AoC2022/01/solver.lisp (limited to 'AoC2022/01/solver.lisp') 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) -- cgit v1.2.3