added nCk calculation, don't know the limit...
This commit is contained in:
1 parent
88630e5161
commit
7ae85dcfe3
1 file changed
+25
@@ -11,6 +11,31 @@ namespace Vocaluxe.Menu
|
|||||||
{
|
{
|
||||||
public class CHelper
|
public class CHelper
|
||||||
{
|
{
|
||||||
|
public static int nCk(int n, int k)
|
||||||
|
{
|
||||||
|
if (k > n)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (k == 0 || k == n)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (k < 0 || n <= 0)
|
||||||
|
return 0; //is not defined
|
||||||
|
|
||||||
|
if (k * 2 > n)
|
||||||
|
k = n - k;
|
||||||
|
|
||||||
|
long result = n;
|
||||||
|
long nl = n;
|
||||||
|
long nk = k;
|
||||||
|
|
||||||
|
for (long i = 1; i <= k - 1; i++)
|
||||||
|
{
|
||||||
|
result = result * (n - i) / (i + 1);
|
||||||
|
}
|
||||||
|
return (int)result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Concat strings into one string with ", " as separator.
|
/// Concat strings into one string with ", " as separator.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in new issue
Block a user