Last active
March 18, 2017 16:09
-
-
Save sw-samuraj/5d2a0b922e40dc16f75035a789db8e97 to your computer and use it in GitHub Desktop.
Counts a Catalan number through a binomial coefficient.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn factorial [n] | |
"Counts a factorial." | |
(reduce *' (range 1 (inc n)))) | |
(defn binomial [n k] | |
"Counts a binomial coefficient." | |
(/ (factorial n) | |
(*' (factorial k) | |
(factorial (- n k))))) | |
(defn catalan [n] | |
"Counts a Catalan number." | |
(* (/ 1 (inc n)) | |
(binomial (* 2 n) n))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment