1 (in-package #:adventofcode2020)
8 (defun int-list-from (str)
9 (mapcar #'parse-integer (list-from str)))
11 (defun list-list-from (str)
12 (split-sequence "" (list-from str) :test #'string=))
14 (defun cartesian-product (A B &rest C)
15 (let ((helper (lambda (X Y)
16 (if Y (loop for x in X
17 nconc (loop for y in Y
18 collecting (append x (list y))))
20 (wrap-A (mapcar #'list A)))
21 (reduce helper C :initial-value (funcall helper wrap-A B))))
28 '((a a) (a b) (b a) (b b))
29 (cartesian-product '(a b) '(a b)))))
33 '((a a a) (a a b) (a b a) (a b b)
34 (b a a) (b a b) (b b a) (b b b))
35 (cartesian-product '(a b) '(a b) '(a b)))))
39 '((a a a a) (a a a b) (a a b a) (a a b b) (a b a a) (a b a b) (a b b a) (a b b b)
40 (b a a a) (b a a b) (b a b a) (b a b b) (b b a a) (b b a b) (b b b a) (b b b b))
41 (cartesian-product '(a b) '(a b) '(a b) '(a b)))))