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/makefile | 13 +++++++++++++ AoC2022/01/solver.el | 9 +++------ AoC2022/01/solver.lisp | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 AoC2022/01/makefile create mode 100755 AoC2022/01/solver.lisp 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 ;; 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) -- cgit v1.2.3