http://t3x.org/klisp/klsys/comb

KLSYS Example Programs

Combinations of a Set

towers of hanoi  |  Takeuchi function  |  combinations of a set  |  letrec macro

; (comb n a)    =  N-combinations of set A
; (comb n a t)  =  with repetition

(defun comb (n a . r)
  (labels
    ((comb (n a)
       (cond
         ((zerop n) nil)
         ((eqv 1 n) (mapcar list a))
         (t (mapcan
              (lambda (tl)
                (mapcar
                  (lambda (u)
                    (cons (car tl) u))
                  (comb (sub1 n)
                        (if r tl (cdr tl)))))
              (maplist (lambda (x) x) a))))))
    (comb n a)))

contact  |  privacy