Skip to content

Instantly share code, notes, and snippets.

@sw-samuraj
Created March 18, 2017 14:26
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 sw-samuraj/41a0e46e05298c3a941c98531ac81648 to your computer and use it in GitHub Desktop.
Save sw-samuraj/41a0e46e05298c3a941c98531ac81648 to your computer and use it in GitHub Desktop.
Counts a Catalan number through recursion.
(defn catalan [n]
"Counts a Catalan number by recursion."
(loop [cnt n acc 1]
(if (zero? cnt)
acc
(recur (dec cnt)
(* acc (- 4 (/ 6 (inc cnt))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment