From 3d57434c04a669610d5f15bd2a7713e6928cdef7 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Thu, 30 Nov 2023 22:46:45 -0700 Subject: add aoc2023 --- aoc_2022/day-03/.gitkeep | 0 aoc_2022/day-03/sol.lisp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 aoc_2022/day-03/.gitkeep create mode 100644 aoc_2022/day-03/sol.lisp (limited to 'aoc_2022/day-03') diff --git a/aoc_2022/day-03/.gitkeep b/aoc_2022/day-03/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-03/sol.lisp b/aoc_2022/day-03/sol.lisp new file mode 100644 index 0000000..7f9ba90 --- /dev/null +++ b/aoc_2022/day-03/sol.lisp @@ -0,0 +1,33 @@ +(ql:quickload "cl-ppcre") + +(defun get-ranges (line) + (ppcre:register-groups-bind ((#'parse-integer first second third fourth)) + ("(\\d+)-(\\d+),(\\d+)-(\\d+)" line :sharedp t) + `((,first ,second) (,third ,fourth)))) + +(defun ranges-may-subset-of-one (a b) + (member-if + (lambda (r) + (and + (>= (caar r) (caadr r)) + (<= (cadar r) (cadadr r)))) + `((,a ,b) (,b ,a)))) + +(defun range-is-contained-at-all (a b) + (and + (<= (car a) (cadr b)) + (>= (cadr a) (car b)))) + +(defun main () + (let ((lines (uiop:read-file-lines "input"))) + (print + (mapcar (lambda (f) + (reduce (lambda (a x) + (if (apply f (get-ranges x)) + (1+ a) + a)) + lines + :initial-value 0)) + '(range-is-contained range-may-be-subset-of-one))))) + +(main) -- cgit v1.2.3-70-g09d2