Exemplo n.º 1
0
        /// <summary>
        /// Sets the current algorithm for GCD calculations.
        /// </summary>
        /// <param name="algorithm">Type of algorithm.</param>
        internal void SetAlgorithm(TypeOfAlgorithm algorithm)
        {
            switch (algorithm)
            {
            case TypeOfAlgorithm.classic:
                currentAlgorithm = gcdOfTwo;
                break;

            case TypeOfAlgorithm.Stein:
                currentAlgorithm = gcdByStein;
                break;

            default:
                break;
            }
        }
 private static int GetGcd(out long time, int a, int b, int c, GcdDelegate gcdFunc)
 {
     return gcdFunc(out time, gcdFunc(out time, a, b), c);
 }
 private static int GetGcd(out long time, int[] array, GcdDelegate gcdFunc)
 {
     var stopWatch = Stopwatch.StartNew();
     int result = array[0];
     for (int i = 1; i < array.Length; i++)
         result = gcdFunc(out time, result, array[i]);
     stopWatch.Stop();
     time = stopWatch.ElapsedTicks;
     return result;
 }