Пример #1
0
 /// <summary>
 /// Calculates the total number of permutations that will be returned.
 /// As this can grow very large, extra effort is taken to avoid overflowing the accumulator.
 /// While the algorithm looks complex, it really is just collecting numerator and denominator terms
 /// and cancelling out all of the denominator terms before taking the product of the numerator terms.
 /// </summary>
 /// <returns>The number of permutations.</returns>
 private long GetCount()
 {
     try
     {
         int        runCount   = 1;
         List <int> divisors   = new List <int>();
         List <int> numerators = new List <int>();
         for (int i = 1; i < myLexicographicOrders.Length; ++i)
         {
             numerators.AddRange(SmallPrimeUtility.Factor(i + 1));
             if (myLexicographicOrders[i] == myLexicographicOrders[i - 1])
             {
                 ++runCount;
             }
             else
             {
                 for (int f = 2; f <= runCount; ++f)
                 {
                     divisors.AddRange(SmallPrimeUtility.Factor(f));
                 }
                 runCount = 1;
             }
         }
         for (int f = 2; f <= runCount; ++f)
         {
             divisors.AddRange(SmallPrimeUtility.Factor(f));
         }
         return(SmallPrimeUtility.EvaluatePrimeFactors(SmallPrimeUtility.DividePrimeFactors(numerators, divisors)));
     }
     catch //????? Code above throws OutOfIndex exception. Needs investigation !!!!!
     {
         return(0L);
     }
 }
Пример #2
0
            /// <summary>
            /// Calculates the total number of permutations that will be returned.
            /// As this can grow very large, extra effort is taken to avoid overflowing the accumulator.
            /// While the algorithm looks complex, it really is just collecting numerator and denominator terms
            /// and cancelling out all of the denominator terms before taking the product of the numerator terms.
            /// </summary>
            /// <returns>The number of permutations.</returns>
            private long GetCount()
            {
                int        runCount   = 1;
                List <int> divisors   = new List <int>();
                List <int> numerators = new List <int>();

                for (int i = 1; i < myLexicographicOrders.Length; ++i)
                {
                    numerators.AddRange(SmallPrimeUtility.Factor(i + 1));
                    if (myLexicographicOrders[i] == myLexicographicOrders[i - 1])
                    {
                        ++runCount;
                    }
                    else
                    {
                        for (int f = 2; f <= runCount; ++f)
                        {
                            divisors.AddRange(SmallPrimeUtility.Factor(f));
                        }
                        runCount = 1;
                    }
                }
                for (int f = 2; f <= runCount; ++f)
                {
                    divisors.AddRange(SmallPrimeUtility.Factor(f));
                }
                return(SmallPrimeUtility.EvaluatePrimeFactors(SmallPrimeUtility.DividePrimeFactors(numerators, divisors)));
            }