Skip to content

Instantly share code, notes, and snippets.

@valvallow
Created February 10, 2010 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valvallow/300237 to your computer and use it in GitHub Desktop.
Save valvallow/300237 to your computer and use it in GitHub Desktop.
combination
(define combination
(lambda (r l)
(cond
((null? l) '())
((or (zero? r)(> r (length l))) '())
((= r 1)(map list l))
((= r (length l))(list l))
(else (append (map (lambda (n)(cons (car l) n))
(combination (- r 1)(cdr l)))
(combination r (cdr l)))))))
(combination 5 '(a b c d e f g))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment