Exemplo n.º 1
0
 private static PayloadInt _run1(GcdStart state)
 {
     while (state.A != state.B)
     {
         state = state.A > state.B ? new GcdStart(state.A - state.B, state.A)
                : state.A < state.B ? new GcdStart(state.A, state.B - state.A)
                                    : state;
     }
     return(new PayloadInt(state, state.A));
 }
Exemplo n.º 2
0
            private static PayloadInt _run2(GcdStart state)
            {
                while (state.A != state.B)
                {
                    var x = state.A; var y = state.B;

                    state = x > y    ? new GcdStart(x - y, x)
                           :    x < y    ? new GcdStart(x, y - x)
                                               : state;
                }
                return(new PayloadInt(state, state.A));
            }
Exemplo n.º 3
0
        static void Main()
        {
            BasicTest();

            WesDyerTest();

            MikeHadlowTest();

            ExternalStateTest();

            GcdTest1(new List <int>()
            {
                24, 60, 42, 48, 9
            }.AsReadOnly());

            var start = new GcdStart(40, 1024);

  #if true
            Gcd_S4.Best.Run(start).ToMaybe().SelectMany(result => {
                var value = result.Value;
                var title = Gcd_S4.GetTitle(Gcd_S4.Best.Run);
                Console.WriteLine("    GCD = {0} for {1} - {2}", value.Gcd, start, title);
                Console.WriteLine();
                return(Maybe.Unit);
            });
  #else
            var result8 = Gcd_S4.Best.Run(start);
            if (result8 != null)
            {
                var value = result8.Value;
                var title = Gcd_S4.GetTitle(Gcd_S4.Best.Run);
                Console.WriteLine("    GCD = {0} for {1} - {2}", value.Gcd, start, title);
                Console.WriteLine();
            }
  #endif

            Console.ReadLine();
        }