;;; Function that returns all possible choices of K elements from a ;;; given list L. Solution courtesy of Martin Buchmann, with cosmetic ;;; editions by JM. (defun combination (k l) (cond ((< k 0) nil) ((= k 0) (list nil)) ((> k (length l)) nil) (t (append (mapcar #'(lambda (x) (cons (first l) x)) (combination (1- k) (rest l))) (combination k (rest l)) ) ) ) )