コード例 #1
0
        private long GetCount()
        {
            int        num   = 1;
            List <int> list  = new List <int>();
            List <int> list2 = new List <int>();

            for (int i = 1; i < this.myLexicographicOrders.Length; i++)
            {
                list2.AddRange(SmallPrimeUtility.Factor(i + 1));
                if (this.myLexicographicOrders[i] == this.myLexicographicOrders[i - 1])
                {
                    num++;
                }
                else
                {
                    for (int j = 2; j <= num; j++)
                    {
                        list.AddRange(SmallPrimeUtility.Factor(j));
                    }
                    num = 1;
                }
            }
            for (int k = 2; k <= num; k++)
            {
                list.AddRange(SmallPrimeUtility.Factor(k));
            }
            return(SmallPrimeUtility.EvaluatePrimeFactors(SmallPrimeUtility.DividePrimeFactors(list2, list)));
        }
コード例 #2
0
ファイル: Permutations.cs プロジェクト: dunder/advent-of-code
        /// <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)));
        }
コード例 #3
0
 static SmallPrimeUtility()
 {
     SmallPrimeUtility.myPrimes = new List <int>();
     SmallPrimeUtility.CalculatePrimes();
 }