Update of /cvsroot/quantproject/QuantProject/b1_ADT/Statistics/Combinatorial
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv10282/b1_ADT/Statistics/Combinatorial
Modified Files:
Combination.cs
Log Message:
The TotalNumberOfCombinations property has been added (to be read to know how many combinations will be generated)
Index: Combination.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Statistics/Combinatorial/Combination.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Combination.cs 21 Aug 2006 19:45:05 -0000 1.1
--- Combination.cs 8 Sep 2006 15:34:41 -0000 1.2
***************
*** 16,23 ****
--- 16,33 ----
private int length;
+ /// <summary>
+ /// each combination length
+ /// </summary>
public int Length
{
get { return this.length; }
}
+ public long TotalNumberOfCombinations
+ {
+ get
+ {
+ return this.totalNumberOfCombinations();
+ }
+ }
/// <summary>
***************
*** 129,132 ****
--- 139,163 ----
return this.currentCombinationValues[ elementIndex ];
}
+ #region totalNumberOfCombinations
+ private long totalNumberOfCombinations_getNumerator()
+ {
+ int firstFactor = this.maxValue - this.minValue + 1;
+ long numerator = 1;
+ for ( int factor = firstFactor ; factor > firstFactor - this.length ;
+ factor -- )
+ numerator *= factor;
+ return numerator;
+ }
+ private long totalNumberOfCombinations_getDenominator()
+ {
+ return ExtendedMath.Factorial( this.length );
+ }
+ private long totalNumberOfCombinations()
+ {
+ long numerator = this.totalNumberOfCombinations_getNumerator();
+ long denominator = this.totalNumberOfCombinations_getDenominator();
+ return numerator / denominator;
+ }
+ #endregion
}
}
|