blob: 23ddfc9991876aed51c324e6d353fdfda201d6f1 (
plain)
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
26
27
|
(require 'common-list-functions)
(define (permute lst)
(define (aux set head)
(cond ((null? set) head)
(else
(map (lambda (x)
(aux (set-difference set (list x))
(cons x head)))
set))))
(aux lst '()))
(define (permute-2 lst)
(let ((result '()))
(define (aux set head)
(if (null? set)
(set! result (cons head result))
(for-each (lambda (x)
(aux (set-difference set (list x))
(cons x head)))
set)))
(aux lst '())
result))
|