aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/01/solver.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'AoC2022/01/solver.lisp')
-rwxr-xr-xAoC2022/01/solver.lisp23
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)