Пример #1
0
        static void Main(string[] args)
        {
            // Alla harjoitus 2

            //Punainen viiva LongestRepetition alla ei mene pois
            LongestRepetition p = new LongestRepetition();

            Console.WriteLine(p.Calculate(new int[] { 1, 2, 1, 1, 2 })); // 2
            Console.WriteLine(p.Calculate(new int[] { 1, 2, 3, 4, 5 })); // 1
            Console.WriteLine(p.Calculate(new int[] { 1, 1, 1, 1, 1 })); // 5



            // Alla harjoitus 1

            /*      Effi pl = new Effi();
             *   Console.WriteLine(pl.Something("10"));
             *   Console.WriteLine(pl.Something("100"));
             *   Console.WriteLine(pl.Something("1000"));
             *   Console.WriteLine(pl.Something("10000"));
             *
             *
             *   Console.WriteLine();
             *
             *   Console.WriteLine(pl.Somethingmore("10"));
             *   Console.WriteLine(pl.Somethingmore("100"));
             *   Console.WriteLine(pl.Somethingmore("1000"));
             *   Console.WriteLine(pl.CreateInput(10000)); */


            /* Effi counters = new Effi();
             * string input10 = counters.CreateInput(10);
             * string input100 = counters.CreateInput(100);
             * string input1000 = counters.CreateInput(1000);
             * string input10000 = counters.CreateInput(10000);
             * string input1000000 = counters.CreateInput(1000000);
             *
             * DateTime start = DateTime.Now;
             * counters.Something(input10); //O(n^2)
             * counters.Something(input100); //O(n^2)
             * counters.Something(input1000); //O(n^2)
             * counters.Something(input10000); //O(n^2)
             *
             *
             * DateTime end = DateTime.Now;
             * Console.WriteLine("Time this took: " + end.Subtract(start));
             *
             * DateTime start1 = DateTime.Now;
             * counters.Somethingmore(input10); //O(n^2)
             * counters.Somethingmore(input100); //O(n^2)
             * counters.Somethingmore(input1000); //O(n^2)
             * counters.Somethingmore(input10000); //O(n^2)
             *
             *
             * DateTime end1 = DateTime.Now;
             * Console.WriteLine("Time this took: " + end1.Subtract(start1));
             *
             */
        }
Пример #2
0
        public void Start()
        {   /*
             * LongestRepetition lr = new LongestRepetition();
             * int[] nmbrs = lr.CreateInput(20);
             * lr.PrintArray(nmbrs);
             * int result = lr.Calculate(nmbrs);
             * System.Console.WriteLine("Max length {0} ", result);
             */
            LongestRepetition p = new LongestRepetition();

            Console.WriteLine(p.Calculate(new int[] { 1, 2, 1, 1, 2 })); // 2
            Console.WriteLine(p.Calculate(new int[] { 1, 2, 3, 4, 5 })); // 1
            Console.WriteLine(p.Calculate(new int[] { 1, 1, 1, 1, 1 })); // 5

            Console.WriteLine("ti2 done");
        }
Пример #3
0
        static void Main(string[] args)
        {
            Compare compare = new Compare();

            string input10    = compare.CreateInput(10);
            string input100   = compare.CreateInput(100);
            string input1000  = compare.CreateInput(1000);
            string input10000 = compare.CreateInput(10000);

            Console.WriteLine("Case1, the inefficient version");

            compare.Case1(input10);
            compare.Case1(input100);
            compare.Case1(input1000);
            compare.Case1(input10000);

            Console.WriteLine("Case2, the efficient version");

            compare.Case2(input10);
            compare.Case2(input100);
            compare.Case2(input1000);
            compare.Case2(input10000);

            Console.WriteLine();

            LongestRepetition p = new LongestRepetition();

            Console.WriteLine(p.Calculate(new int[] { 1, 2, 1, 1, 2 }));                       // 2
            Console.WriteLine(p.Calculate(new int[] { 1, 2, 3, 4, 5 }));                       // 1
            Console.WriteLine(p.Calculate(new int[] { 1, 1, 1, 1, 1 }));                       // 5
            Console.WriteLine(p.Calculate(new int[] { 0, 0, 1, 2, 2, 2, 7, 0, 0, 0, 0, 13 })); // 4



            Console.WriteLine();

            Changes m = new Changes();

            Console.WriteLine(m.Calculate(new int[] { 1, 1, 2, 2, 2 }));          // 2
            Console.WriteLine(m.Calculate(new int[] { 1, 2, 3, 4, 5 }));          // 0
            Console.WriteLine(m.Calculate(new int[] { 1, 1, 1, 1, 1 }));          // 2
            Console.WriteLine(m.Calculate(new int[] { 0, 0, 0, 1, 1, 1, 0, 0 })); // 3
            Console.WriteLine(m.Calculate(new int[] { 0, 0, 0, 0, 0 }));          // 2
            Console.WriteLine(m.Calculate(new int[] { 1, 1, 1, 1 }));             // 2
            Console.WriteLine(m.Calculate(new int[] { 0, 0, 0, 0 }));             // 2

            Console.WriteLine();

            Revolutions r = new Revolutions();

            Console.WriteLine(r.Calculate(new int[] { 4, 1, 3, 2, 5 }));                 // 3
            Console.WriteLine(r.Calculate(new int[] { 1, 2, 3, 4, 5 }));                 // 1
            Console.WriteLine(r.Calculate(new int[] { 5, 4, 3, 2, 1 }));                 // 5
            Console.WriteLine(r.Calculate(new int[] { 1, 3, 5, 7, 9, 2, 4, 6, 8, 10 })); //5

            Console.WriteLine();

            Split s = new Split();

            Console.WriteLine(s.Calculate(new int[] { 1, 2, -1, 4, 0 }));   // 1
            Console.WriteLine(s.Calculate(new int[] { 1, 2, 3, 4, 5 }));    // 0
            Console.WriteLine(s.Calculate(new int[] { 0, 0, 0, 0, 0 }));    // 4
            Console.WriteLine(s.Calculate(new int[] { 2, 2, 2, 2, 2, 2 })); // 1
        }