From c7e72e49e0e98dd85362314eb97d8f384169556f Mon Sep 17 00:00:00 2001 From: 4903000 <4903000@chiru.no> Date: Sun, 6 Dec 2020 10:35:33 +0000 Subject: [PATCH] Day 6 --- aoc20.lisp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/aoc20.lisp b/aoc20.lisp index f68d5f3..e30fb7c 100644 --- a/aoc20.lisp +++ b/aoc20.lisp @@ -212,3 +212,22 @@ (time (progn (print (solve-5-1 (copy-seq data))) (solve-5-2 data) (print p1-answer))))) + +(defun read-forms (stream) + (loop for line = (read-line stream nil) + while (and line (not (string= line ""))) + collect line)) + +(defun read-6 (file) + (with-open-file (stream file) + (loop while (peek-char nil stream nil) + collect (read-forms stream)))) + +(defun solve-6-1 (data) + (reduce (lambda (x y) (+ (if (consp x) (length x) x) (length y))) + (map 'list (lambda (form) (remove-duplicates (apply #'concatenate 'list form))) data))) + +(defun solve-6-2 (data) + (length (mapcan (lambda (entry) + (reduce #'intersection (map 'list (lambda (l) (coerce l 'list)) entry))) + data)))