Add solution for day 4

This commit is contained in:
Tobias Eidelpes 2022-12-04 14:49:41 +01:00
parent 85af020ca8
commit 79b9b696d0
2 changed files with 1028 additions and 0 deletions

28
day04/day04.lisp Normal file
View File

@ -0,0 +1,28 @@
(ql:quickload :cl-ppcre)
(defun string-to-sequence (range)
(let* ((range (cl-ppcre:split "-" range))
(lower (parse-integer (first range)))
(upper (parse-integer (second range))))
(loop :for x :from lower :to upper :collect x)))
(defun parse-input (input)
(cl-ppcre:split "\\n" (uiop:read-file-string input)))
(defun containp (pair)
(let ((left (string-to-sequence (first (ppcre:split "," pair))))
(right (string-to-sequence (second (ppcre:split "," pair)))))
(cond ((search left right) t)
((search right left) t)
(t NIL))))
(defun part-one (input)
(count 't (mapcar #'containp (parse-input input))))
(defun overlapp (pair)
(let ((left (string-to-sequence (first (ppcre:split "," pair))))
(right (string-to-sequence (second (ppcre:split "," pair)))))
(if (intersection left right) t)))
(defun part-two (input)
(count 't (mapcar #'overlapp (parse-input input))))

1000
day04/input Normal file

File diff suppressed because it is too large Load Diff