day 4 part 2 in elisp

This commit is contained in:
cow 2022-12-08 02:25:31 -05:00
parent a4145962b8
commit 8ff58bfa0d
4 changed files with 12 additions and 12 deletions

View file

@ -0,0 +1 @@
../advent-of-code.el

1
elisp/day-4/example.txt Symbolic link
View file

@ -0,0 +1 @@
../../input/day-4-example.txt

1
elisp/day-4/input.txt Symbolic link
View file

@ -0,0 +1 @@
../../input/day-4.txt

View file

@ -17,18 +17,11 @@
;; You should have received a copy of the GNU General Public License ;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(add-to-list 'load-path "../") (add-to-list 'load-path default-directory)
(require 'ert) (require 'ert)
(require 'cl-lib)
(require 'advent-of-code) (require 'advent-of-code)
(defvar solution-input
"../../input/day-4.txt")
(defvar solution-example-input
"../../input/day-4-example.txt")
(defun solution-parse-pair (s) (defun solution-parse-pair (s)
(let ((parts (string-split s "-"))) (let ((parts (string-split s "-")))
(cons (string-to-number (car parts)) (cons (string-to-number (car parts))
@ -64,16 +57,20 @@
pairs))) pairs)))
(ert-deftest solution-part-1-example () (ert-deftest solution-part-1-example ()
(should (equal (solution-part-1 (aoc-read-file-lines solution-example-input)) 2))) (should (equal (solution-part-1 (aoc-read-file-lines "example.txt")) 2)))
(ert-deftest solution-part-1 () (ert-deftest solution-part-1 ()
(should (equal (solution-part-1 (aoc-read-file-lines solution-input)) 644))) (should (equal (solution-part-1 (aoc-read-file-lines "input.txt")) 644)))
(ert-deftest solution-part-2-example ()
(should (equal (solution-part-2 (aoc-read-file-lines "example.txt")) 4)))
(ert-deftest solution-part-2 ()
(should (equal (solution-part-2 (aoc-read-file-lines "input.txt")) 926)))
(when noninteractive (when noninteractive
(ert-run-tests-batch)) (ert-run-tests-batch))
;; Code
;; Local Variables: ;; Local Variables:
;; read-symbol-shorthands: (("solution-" . "advent-of-code-day-4-") ("aoc-" . "advent-of-code-")) ;; read-symbol-shorthands: (("solution-" . "advent-of-code-day-4-") ("aoc-" . "advent-of-code-"))
;; End: ;; End: