Skip to content

Instantly share code, notes, and snippets.

@andrewhavck
Created January 10, 2011 01:31
Show Gist options
  • Save andrewhavck/772224 to your computer and use it in GitHub Desktop.
Save andrewhavck/772224 to your computer and use it in GitHub Desktop.
(defn factorial [n]
(loop [iter n, res 1]
(cond
(zero? iter) res
:else (recur (dec iter) (* res iter)))))
(defn combination [n k]
(/ (factorial n) (* (factorial (- n k)) (factorial k))))
(comment k = number of hot dogs)
(comment n = number of toppings)
(comment Doesn't count the plain case)
(defn number-of-combinations [n k]
(* (reduce + (map combination (repeat n n) (range n))) k))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment