tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
11
Task/Permutations/Scheme/permutations-3.ss
Normal file
11
Task/Permutations/Scheme/permutations-3.ss
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(define (perm s)
|
||||
(cond ((null? s) '())
|
||||
((null? (cdr s)) (list s))
|
||||
(else ;; extract each item in list in turn and perm the rest
|
||||
(let splice ((l '()) (m (car s)) (r (cdr s)))
|
||||
(append
|
||||
(map (lambda (x) (cons m x)) (perm (append l r)))
|
||||
(if (null? r) '()
|
||||
(splice (cons m l) (car r) (cdr r))))))))
|
||||
|
||||
(display (perm '(1 2 3)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue