aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/01/solver.el
diff options
context:
space:
mode:
Diffstat (limited to 'AoC2022/01/solver.el')
-rw-r--r--AoC2022/01/solver.el40
1 files changed, 17 insertions, 23 deletions
diff --git a/AoC2022/01/solver.el b/AoC2022/01/solver.el
index 67c1980..ec5710f 100644
--- a/AoC2022/01/solver.el
+++ b/AoC2022/01/solver.el
@@ -19,30 +19,24 @@
;;
;;; Code:
(require 'seq)
+(defun solver-elves-rations ()
+ (with-temp-buffer
+ (insert-file-contents "input")
+ (thread-last
+ (split-string (buffer-string) "\n\n")
+ (mapcar
+ (lambda (elf)
+ (seq-reduce (lambda (acc x)
+ (+ acc (string-to-number x)))
+ (split-string elf) 0))))))
+
+(ert-deftest solutions ()
+ (let ((rations (solver-elves-rations)))
+ ;; calculate the maximum from each elves rations
+ (should (= 75622 (apply #'max rations)))
+ ;; calculate the maximum from each elves rations
+ (should (= 213159 (apply #'+ (seq-take (sort rations #'>) 3))))))
-;; calculate the maximum from each elves rations
-(with-temp-buffer
- (insert-file-contents "input")
- (apply #'max
- (mapcar
- (lambda (elf)
- (seq-reduce (lambda (acc x)
- (+ acc (string-to-number x)))
- (split-string elf) 0))
- (split-string (buffer-string) "\n\n"))))
-;; calculate the maximum from each elves rations
-(with-temp-buffer
- (insert-file-contents "input")
- (apply #'+
- (thread-first
- (mapcar
- (lambda (elf)
- (seq-reduce (lambda (acc x)
- (+ acc (string-to-number x)))
- (split-string elf) 0))
- (split-string (buffer-string) "\n\n"))
- (sort #'>)
- (seq-take 3))))
(provide 'solver)
;;; solver.el ends here