Skip to content

Instantly share code, notes, and snippets.

@CGA1123
Last active December 15, 2015 21:43
Show Gist options
  • Save CGA1123/e6854842d5c818b36795 to your computer and use it in GitHub Desktop.
Save CGA1123/e6854842d5c818b36795 to your computer and use it in GitHub Desktop.
Catalan Numbers in SML
(* 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