X-Git-Url: http://git.jkinsey.net/?p=adventofcode2020.git;a=blobdiff_plain;f=src%2Fday06.lisp;fp=src%2Fday06.lisp;h=e116865cd5d652ed0a27d7b14671ae40b815a0f9;hp=0000000000000000000000000000000000000000;hb=007500675a2dd10e250d3ad0588852ed6f9225a6;hpb=d1bbb525d19c4ff491795ed6365d7203d49a7f6d diff --git a/src/day06.lisp b/src/day06.lisp new file mode 100644 index 0000000..e116865 --- /dev/null +++ b/src/day06.lisp @@ -0,0 +1,36 @@ +(asdf:load-system :adventofcode2020) +(in-package #:adventofcode2020) +(named-readtables:in-readtable fn-reader) + +(defun count-answers (join ans-list) + (->> ans-list + (mapcar λ(map 'list #'identity _)) + (reduce λ(funcall join _0 _1 :test #'char=)) + (length))) + +(day 06 input + (let ((answer-groups (-<>> (list-from input) + (split-sequence "" <> :test #'string=))) + (disjunction (curry #'count-answers #'union)) + (conjunction (curry #'count-answers #'intersection) )) + (part1 (->> answer-groups (mapcar disjunction) (reduce #'+))) + (part2 (->> answer-groups (mapcar conjunction) (reduce #'+))))) + +(def-suite day06) +(in-suite day06) + +(test count-answers-disj + (is (equal + '(3 3 3 1 1) + (mapcar (curry #'count-answers #'union) + '(("abc") ("a" "b" "c") ("ab" "ac") + ("a" "a" "a" "a") ("b")))))) + +(test count-answers-conj + (is (equal + '(3 0 1 1 1) + (mapcar (curry #'count-answers #'intersection) + '(("abc") ("a" "b" "c") ("ab" "ac") + ("a" "a" "a" "a") ("b")))))) + +(run! 'day06)