Skip to content

Instantly share code, notes, and snippets.

@oremj
Created January 13, 2010 18:23
Show Gist options
  • Save oremj/276428 to your computer and use it in GitHub Desktop.
Save oremj/276428 to your computer and use it in GitHub Desktop.
-module(combin).
-export([factorial/1, combination/2, prob15/1]).
factorial(N) -> factorial(N, 1).
factorial(1, Acc) -> Acc * 1;
factorial(N, Acc) -> factorial(N - 1, N * Acc).
combination(N,K) -> factorial(N) div (factorial(K) * factorial(N - K)).
prob15(X) -> combination(X * 2, X).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment