CFLib.org – Common Function Library Project

Combination(n, p)

Last updated July 18, 2001

author

Joel Cox

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Returns the Combination of n elements taken p at a time.

Return Values:
Returns a simple value

Example:

<CFSET n=13>
  <CFSET p=2>
  <CFOUTPUT>
  Given n=13, p=2
  Combination(n,p) is #Combination(n,p)#
  </CFOUTPUT>

Parameters:

Name Description Required
n Any non-negative integer Yes
p any non-negative integer, <= n Yes

Full UDF Source:

/**
 * Returns the Combination of n elements taken p at a time.
 * This funciton requires the Permutation() and Factorial() functions from this library.
 * 
 * @param n 	 Any non-negative integer 
 * @param p 	 any non-negative integer, <= n 
 * @return Returns a simple value 
 * @author Joel Cox (jlcox@goodyear.com) 
 * @version 1, July 18, 2001 
 */
function Combination(n,p)
{
  var RetVal = 0;
  if (p GT n) {
   RetVal = "undefined";
  }
  else
   RetVal = Permutation(n,p) / Factorial(p);  
  Return RetVal;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson