Skip to content

Instantly share code, notes, and snippets.

@sheniff
Created April 19, 2015 20:22
Show Gist options
  • Select an option

  • Save sheniff/4a1d2d9a2d31b9d56ddd to your computer and use it in GitHub Desktop.

Select an option

Save sheniff/4a1d2d9a2d31b9d56ddd to your computer and use it in GitHub Desktop.
Catalan Numbers to mathematically verify number of combinations (http://en.wikipedia.org/wiki/Catalan_number)
// Catalan Numbers to mathematically verify number of combinations
// E.g, the number of possible combinations of parentheses
// http://en.wikipedia.org/wiki/Catalan_number
function catalanNumber(numParens) {
var total = 1;
for(var i = 2; i <= numParens; i++) {
total *= (numParens + i) / i;
}
return total;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment