1 (in-package #:adventofcode2020)
8 (defun int-list-from (str)
9 (mapcar #'parse-integer (list-from str)))
11 (defun cartesian-product (A B &rest C)
12 (let ((helper (lambda (X Y)
13 (if Y (loop for x in X
14 nconc (loop for y in Y
15 collecting (append x (list y))))
17 (wrap-A (mapcar #'list A)))
18 (reduce helper C :initial-value (funcall helper wrap-A B))))
25 '((a a) (a b) (b a) (b b))
26 (cartesian-product '(a b) '(a b)))))
30 '((a a a) (a a b) (a b a) (a b b)
31 (b a a) (b a b) (b b a) (b b b))
32 (cartesian-product '(a b) '(a b) '(a b)))))
36 '((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)
37 (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))
38 (cartesian-product '(a b) '(a b) '(a b) '(a b)))))