Add solution for day 4
This commit is contained in:
parent
85af020ca8
commit
79b9b696d0
28
day04/day04.lisp
Normal file
28
day04/day04.lisp
Normal 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
1000
day04/input
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user