Permutations: Difference between revisions
Content deleted Content added
→{{header|AutoHotkey}}: AutoHotkey example |
→{{header|Scheme}}: impl #3 |
||
Line 2,095: | Line 2,095: | ||
; 2 0 1 |
; 2 0 1 |
||
; 2 1 0</lang> |
; 2 1 0</lang> |
||
Completely recursive on lists: |
|||
<lang lisp>(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)))</lang> |
|||
=={{header|Seed7}}== |
=={{header|Seed7}}== |