Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Created October 26, 2008 00:25
Show Gist options
  • Save KirinDave/19820 to your computer and use it in GitHub Desktop.
Save KirinDave/19820 to your computer and use it in GitHub Desktop.
(define (permute terms)
(permute-help terms (length terms)))
(define (permute-help terms descent)
(cond
((= (length terms) 1) (list terms))
((< descent 1) (list))
(else (append
(map (lambda (x) (cons (car terms) x)) (permute-help (cdr terms) (length (cdr terms))))
(permute-help (append (cdr terms) (list (car terms))) (- descent 1))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment