permute
Die Funktion permute liefert die Liste aller Permutationen einer Liste.
Die Funktion permute baut auf if, null?, append, map-with, first, cons, rest und list auf:
(setq permute
(letrec
((permute-help
(lambda (l r)
(if
(null? r)
nil
(append
(map-with (lambda (x) (cons (first r) x))
(permute (append l (rest r))))
(permute-help
(append l (list (first r)))
(rest r)))))))
(lambda (l)
(if
(null? (rest l))
(list l)
(permute-help nil l)))))
Die Funktion permute baut auf if, null?, append, map-with, first, cons, rest und list auf:
(setq permute
(letrec
((permute-help
(lambda (l r)
(if
(null? r)
nil
(append
(map-with (lambda (x) (cons (first r) x))
(permute (append l (rest r))))
(permute-help
(append l (list (first r)))
(rest r)))))))
(lambda (l)
(if
(null? (rest l))
(list l)
(permute-help nil l)))))