RosettaCodeData/Task/Combinations/Acornsoft-Lisp/combinations.lisp

14 lines
345 B
Common Lisp

(defun comb (m n (i . 0))
(cond ((zerop m) '(()))
((eq i n) '())
(t (append
(mapc '(lambda (rest) (cons i rest))
(comb (sub1 m) n (add1 i)))
(comb m n (add1 i))))))
(defun append (a b)
(cond ((null a) b)
(t (cons (car a) (append (cdr a) b)))))
(map print (comb 3 5))