### 求出n取k組合的列表 Lisp版

```(defun addlist(newList)
(setq result (append result (list (reverse newlist))))
)

(defun calc(before all want)
(cond
((= want 0)
(setq rest (loop for i from 1 to all append (list 0)))
((= all want)
(setq left (- all want))
(setq rest (loop for x from 1 to all append  (list 1)))
((= all 1)
(t
(calc (append before (list 0)) (- all 1) want)
(calc (append before (list 1)) (- all 1) (- want 1)))
)
)

(defun combinations (all want)
(setq result (list))
(setq lst (list) )
(calc lst all want)
)

(combinations 3 2)
(print result)```

```(defun addlist(newList)
(setq result (append result (list (reverse newlist))))
)

(defun combinations (all want )
(setq result (list))
(setq lst (loop for x from 1 to all append  (list x)))
(labels ((calc (l c want)
(when (>= (length l) want)
(if (zerop want) (return-from calc (addlist c)))
(calc (cdr l) c want)
(calc (cdr l) (cons (first l) c) (1- want)))))
(calc lst nil want))
(setq result (reverse result))
)

(combinations 3 2)
(print result)```