Permutations: Difference between revisions

Content added Content deleted
(→‎{{header|AutoHotkey}}: AutoHotkey example)
Line 2,095:
; 2 0 1
; 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}}==