public override Int64 Calculate(int source, int maximumCoins, Int64[] newNumberOfCoins)
        {
            Int64 cnt = 0;

            foreach (var c in CoinsByRecursion.TotalCoinsForEachCombinationForValue(coin, source))
            {
                newNumberOfCoins[c]++;
                cnt++;
            }

            return(cnt);
        }
Beispiel #2
0
        public static (IEnumerable <Int64> recursive, IEnumerable <Int64> uneven, IEnumerable <Int64> even) GetResults(
            IEnumerable <Int32> arr, int numberToAdd)
        {
            var targetValue = arr.Sum() + numberToAdd;

            Console.WriteLine("target value is " + targetValue);

            var coin = MagicPurse.GenerateTestCoin(arr.ToList());

            var s = new Stopwatch();

            s.Start();

            var coinBuffer0 = new Int64[targetValue];

            CoinsByRecursion.TotalCoinsForEachCombinationForValue(coinBuffer0, coin, targetValue);

            s.Stop();

            Console.WriteLine($"Elapsed ms - {s.ElapsedMilliseconds}");

            s = new Stopwatch();

            s.Start();

            var coinBuffer1 = GenerateUneven.Generate(arr.ToList(), targetValue);

            s.Stop();

            Console.WriteLine(s.ElapsedMilliseconds);


            s = new Stopwatch();

            s.Start();

            var coinBuffer2 = GenerateEven.Generate(coin, targetValue);

            s.Stop();

            Console.WriteLine(s.ElapsedMilliseconds);

            return(coinBuffer0, coinBuffer1, coinBuffer2);
        }