;;;; Permutation Generator by D. Kuehn (defun flatten (list) (typecase list (atom (list list)) (list (loop for elt in list nconc (flatten elt))))) (defun permutations (list) (if (endp list) (list nil) (mapcar #'(lambda (x) (mapcar #'(lambda (p) (cons x p)) (permutations (remove x list)))) list))) (defun permute (list) (mapcar #'flatten (nconc (mapcar #'car (permutations list)) (mapcar #'cdr (permutations list)))))