/// <summary>
        /// Uses optimises calculation for TotalCoin combinations
        /// because we know we only have Units in our set of coins
        /// that are successive multiples - e.g., 8,4,2,1 ...
        /// so can be optimized to avoid division.
        /// only triggers when the lowest unit fires and
        /// when our startingPoint = unitSum = '15' in above example
        /// is reached.
        /// Stores results in large array provided.  The implementation could be
        /// better de-coupled ... but this is efficient.
        /// </summary>
        /// <param name="source">value to calculate</param>
        /// <<param name="maximumCoins">max coins to generate</param>
        /// <param name="newNumberOfCoins"></param>
        /// <returns>Number of combinations found</returns>
        /// <exception cref="Exception">Exception if internal number of Tickers happens to be wrong ... shouldn;t happen</exception>
        public override Int64 Calculate(int source, int maximumCoins, Int64[] newNumberOfCoins)
        {
            Int64 cnt = 0;

            if (source >= unitSum && source % lowestFactor == 0)
            {
                var vals = ValuesAndMultiplesForEvenFactors.GenerateValuesAndMultiplesRecursive(coin, source).ToList();

                if (vals.Count() == 7)
                {
                    cnt = CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(newNumberOfCoins, maximumCoins, source, vals[0], vals[1], vals[2], vals[3], vals[4], vals[5], vals[6]);
                }
                else if (vals.Count() == 6)
                {
                    cnt = CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(newNumberOfCoins, maximumCoins, source, vals[0], vals[1], vals[2], vals[3], vals[4], vals[5]);
                }
                else if (vals.Count() == 5)
                {
                    cnt = CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(newNumberOfCoins, maximumCoins, source, vals[0], vals[1], vals[2], vals[3], vals[4]);
                }
                else if (vals.Count() == 4)
                {
                    cnt = CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(newNumberOfCoins, maximumCoins, source, vals[0], vals[1], vals[2], vals[3]);
                }
                else if (vals.Count() == 3)
                {
                    cnt = CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(newNumberOfCoins, maximumCoins, source, vals[0], vals[1], vals[2]);
                }
                else if (vals.Count() == 2)
                {
                    cnt = CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(newNumberOfCoins, maximumCoins, source, vals[0], vals[1]);
                }
                else if (vals.Count() == 1)
                {
                    cnt = CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(newNumberOfCoins, maximumCoins, source, vals[0]);
                }
                else
                {
                    throw new Exception($"Unexpected number of values initialized - {vals.Count} > 7");
                }
            }

            return(cnt);
        }
Exemple #2
0
        public static IEnumerable <Int64> Generate(CoinsLib.CombinationCalculator.Coin foo, int value, int max = 10000)
        {
            var arr = new Int64[value];

            var g = ValuesAndMultiplesForEvenFactors.GenerateValuesAndMultiplesRecursive(foo, value).ToArray();

            if (g.Length == 7)
            {
                CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(arr, max, value, g[0], g[1], g[2], g[3], g[4], g[5], g[6]);
            }
            if (g.Length == 6)
            {
                CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(arr, max, value, g[0], g[1], g[2], g[3], g[4], g[5]);
            }
            if (g.Length == 5)
            {
                CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(arr, max, value, g[0], g[1], g[2], g[3], g[4]);
            }
            if (g.Length == 4)
            {
                CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(arr, max, value, g[0], g[1], g[2], g[3]);
            }
            if (g.Length == 3)
            {
                CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(arr, max, value, g[0], g[1], g[2]);
            }
            if (g.Length == 2)
            {
                CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(arr, max, value, g[0], g[1]);
            }
            if (g.Length == 1)
            {
                CoinsForEvenFactors.CalculateTotalCoinsForEachComboAndReturnCount(arr, max, value, g[0]);
            }

            return(arr);
        }