From 976fafe4bfee6b66218b0ce0f0481624c5fe2f02 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Sun, 4 Dec 2022 23:17:43 +0100 Subject: [AoC2022] Common Lisp 04-01 --- AoC2022/04/solver.lisp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 AoC2022/04/solver.lisp (limited to 'AoC2022/04/solver.lisp') diff --git a/AoC2022/04/solver.lisp b/AoC2022/04/solver.lisp new file mode 100644 index 0000000..0a4077f --- /dev/null +++ b/AoC2022/04/solver.lisp @@ -0,0 +1,26 @@ +(ql:quickload '(:fiveam :uiop)) + +(defun subinterval (a0 a1 b0 b1) + "Test if [b0;b1] within [a0;a1]" + (and (<= a0 b0 ) (>= a1 b1))) + +(defun sections-contained (line) + (destructuring-bind (a0 a1 b0 b1) + (mapcar #'parse-integer + (uiop:split-string line :separator '(#\, #\-))) + (or (subinterval a0 a1 b0 b1) + (subinterval b0 b1 a0 a1)))) + +(defun count-repeated () + (with-open-file (in "input") + (loop for l = (read-line in nil nil) + while l + count (sections-contained l)))) + + +(fiveam:test results + (fiveam:is (= 515 (count-repeated))) + (fiveam:is (= 2567 (badge)))) + + +(fiveam:run-all-tests) -- cgit v1.2.3