Last active
December 15, 2015 21:43
-
-
Save CGA1123/e6854842d5c818b36795 to your computer and use it in GitHub Desktop.
Catalan Numbers in SML
This file contains 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
(* Catalan Numbers *) | |
open LargeInt; | |
fun fact 0 = 1 | |
| fact n = n * (fact (n-1)); | |
fun catalan n = let val factofn = fact n | |
in (fact (2 * n)) div (((n+1) * factofn) * (factofn)) end; | |
fun firstn f 0 = [f 0] | |
| firstn f n = (f n)::(firstn f (n-1)); | |
val catalanfifteen = rev (firstn catalan 15); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment