(asdf:load-system :adventofcode2020) (in-package #:adventofcode2020) (named-readtables:in-readtable :adventofcode2020) (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)