-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomb
More file actions
25 lines (24 loc) · 728 Bytes
/
comb
File metadata and controls
25 lines (24 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
; (comb n a) = N-combinations of set A
; (comb n a t) = with repetition
(setq comb
(lambda (n a . r)
(labels
((tails
(lambda (a)
(if (null a)
nil
(cons a (tails (cdr a))))))
(comb
(lambda (n a)
(cond
((null n) nil)
((null (cdr n)) (map list a))
(else
(apply conc
(map (lambda (tl)
(map (lambda (u)
(cons (car tl) u))
(comb (cdr n)
(if r tl (cdr tl)))))
(tails a))))))))
(comb n a))))