aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AoC2022/01/makefile13
-rw-r--r--AoC2022/01/solver.el9
-rwxr-xr-xAoC2022/01/solver.lisp23
3 files changed, 39 insertions, 6 deletions
diff --git a/AoC2022/01/makefile b/AoC2022/01/makefile
new file mode 100644
index 0000000..b885a31
--- /dev/null
+++ b/AoC2022/01/makefile
@@ -0,0 +1,13 @@
+##
+# run solutions
+#
+# @file
+# @version 0.1
+
+
+
+# end
+
+run:
+ sbcl --load ~/.sbclrc --script solver.lisp
+ emacs -batch -l ert -l solver.el -f ert-run-tests-batch-and-exit
diff --git a/AoC2022/01/solver.el b/AoC2022/01/solver.el
index ec5710f..8dba125 100644
--- a/AoC2022/01/solver.el
+++ b/AoC2022/01/solver.el
@@ -6,10 +6,6 @@
;; Maintainer: Óscar Nájera <hi@oscarnajera.com>
;; Created: December 02, 2022
;; Modified: December 02, 2022
-;; Version: 0.0.1
-;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp
-;; Homepage: https://github.com/titan/solver
-;; Package-Requires: ((emacs "25.1"))
;;
;; This file is not part of GNU Emacs.
;;
@@ -18,7 +14,10 @@
;; Solution for AoC 2022 day 1
;;
;;; Code:
+
(require 'seq)
+(require 'subr-x)
+
(defun solver-elves-rations ()
(with-temp-buffer
(insert-file-contents "input")
@@ -38,5 +37,3 @@
(should (= 213159 (apply #'+ (seq-take (sort rations #'>) 3))))))
-(provide 'solver)
-;;; solver.el ends here
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)