nCk

From DavinciWiki
Jump to: navigation, search

Description

Combinations (n-choose-k, the binomial coefficient).

Arguments and Return Values

Arguments: Two numeric values (must be scalar)

Return Value: The number of combinations possible when choosing k items from a set of n items (order doesn't matter)

So, to find the number of 5-card hands possible from a 52-card deck, use nCk(52, 5)

nCk(n, k) = n!/(k!*(n-k)!)

This function uses nCk(n, k) = n*(n-1)*(n-2)*...*(n-(k-1))/(k*(k-1)*(k-2)*...*1)

Returns integer when output is small enough to be correctly expressed as an integer; float otherwise

If no arguments are input, nCk() prints its description, as shown below.

Usage

Syntax: nCk(n, k)

'n' - a scalar value specifying the number of items in the set

'k' - a scalar value specifying the number of items to choose

Examples

dv> nCk()

Combinations (a.k.a. n choose k, or the binomial coefficient)
nCk(n,k) returns the number of ways to choose n elements from a
 set of k elements (n >= k; order doesn't matter)
nCk = n!/(k!*(n - k)!)
Does NOT work for arrays, only for 1x1x1 inputs
S.Marshall 02-25-2008

0
dv> nCk(52, 5)
2.59896e+06
dv> nCk(16, 6)
8008
dv> nCk(10, 0)
1
dv> nCk(10, -1)

Inputs must be positive integers

0
dv> nCk(10, 1//2//3)

Inputs must be scalar (1x1x1)

0

DavinciWiki Mini-Nav Bar

Contents


Contact Developers

  • davinci-dev [AT] mars.asu.edu

All other topics

  • See navigation on the left

Major Sub-Functions

Related Functions

Recent Library Changes

Created On: 02-25-2008
Modified On: 02-25-2008

Personal tools