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;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson