Skip to content

Instantly share code, notes, and snippets.

@ldcc
Last active May 24, 2019 02:48
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 ldcc/00e9164840530a5ac18bd2e31b1b79a4 to your computer and use it in GitHub Desktop.
Save ldcc/00e9164840530a5ac18bd2e31b1b79a4 to your computer and use it in GitHub Desktop.
Computes all combinations of r elements from n.
(define combo
(let ([d (- n r)])
(λ (n r)
(/ (factorial n 1)
(factorial r 1)
(factorial d 1)))))
(define factorial
(λ (x s)
(cond [(< x 1) s]
[else
(factorial
(- x 1)
(* x s))])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment