summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/utils/permute.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-core/src/utils/permute.scm')
-rw-r--r--gnuradio-core/src/utils/permute.scm27
1 files changed, 27 insertions, 0 deletions
diff --git a/gnuradio-core/src/utils/permute.scm b/gnuradio-core/src/utils/permute.scm
new file mode 100644
index 000000000..23ddfc999
--- /dev/null
+++ b/gnuradio-core/src/utils/permute.scm
@@ -0,0 +1,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))
+
+
+