(defun all-lists-repeat (m k) (search k m 'list-repeat-expand) ) (defun all-lists-no-repeat (m k) (search k m 'list-no-repeat-expand) ) (defun all-bags-repeat (m k) (remove-duplicates (search k m 'bags-repeat-expand) :test #'tree-equal) ) (defun all-bags-no-repeat (m k) (remove-duplicates (search k m 'bags-no-repeat-expand) :test #'tree-equal) ) (defun search (k m expand) (do ( (items (make-list k)) (queue (mapcar 'list (make-list k)) (append (cdr queue) expansion)) (expansion) ) ((EQUAL (length (car queue)) m) queue) (setq expansion (funcall expand (car queue) items)) ) ) (defun list-repeat-expand (queue items) (mapcar #'(lambda (x) (cons x queue) ) items) ) ) (defun list-no-repeat-expand (queue items) (remove nil (mapcar #'(lambda (x) (cond ((not (member x queue)) (cons x queue)) ) ) items) ) ) ) (defun bags-repeat-expand (queue items) (mapcar #'(lambda (x) (mergesort (cons x queue)) ) items) ) ) (defun bags-no-repeat-expand (queue items) (remove nil (mapcar #'(lambda (x) (cond ((not (member x queue)) (mergesort (cons x queue))) ) ) items) ) ) ) (defun make-list (m) (DO ( (L () (CONS (BUILD-NAME "a" N) L)) (N M (- N 1)) ) ((ZEROP N) L) ) ) (defun build-name (&rest names) (read-from-string (build-string names)) ) (defun build-string (name-list) (cond ((null name-list) nil) (t (concatenate 'string (cond ( (numberp (car name-list)) (princ-to-string (car name-list)) ) ( t (string (car name-list)) ) ) (build-string (cdr name-list)) ) ) ) )