Esempio n. 1
0
        static void Main(string[] args)
        {            //tarea
            Lineal            lineal            = new Lineal();
            LinealExampleType linealExampleType = LinealExampleType.Loop;

            switch (linealExampleType)
            {
            case LinealExampleType.Loop:
                int n = 50;
                lineal.Loop(n);
                break;

            case LinealExampleType.ContainsNeedle:
                List <int> numberList = new List <int>()
                {
                    10, 18, 29, 1, 0, 75, 79
                };
                int  needle = 76;
                bool found  = lineal.ContainsNeedle(needle, numberList);
                Console.WriteLine("Number {0} found? {1}", needle, found);
                break;

            case LinealExampleType.Factorial:
                int  nFactorial = 10;
                long factorial  = lineal.Factorial(nFactorial);
                Console.WriteLine("Factorial of {0} equal to {1}", nFactorial, factorial);
                break;
            }
            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            Lineal            lineal            = new Lineal();
            LinealExampleType linealExampleType = LinealExampleType.Fibonacci;
            int nFibonacciCache = 80; //8 40 80

            lineal.fibonacciCache = new long[nFibonacciCache + 1];
            switch (linealExampleType)
            {
            case LinealExampleType.Loop:
                int n = 50;
                lineal.Loop(n);
                break;

            case LinealExampleType.ContainsNeedle:
                List <int> numberList = new List <int>()
                {
                    10, 18, 29, 1, 0, 75, 79
                };
                int  needle = 76;
                bool found  = lineal.ContainsNeedle(needle, numberList);
                Console.WriteLine("Number {0} found? {1}", needle, found);
                break;

            case LinealExampleType.Factorial:
                int  nFactorial = 10;
                long factorial  = lineal.Factorial(nFactorial);
                Console.WriteLine("Factorial of {0} equal to {1}", nFactorial, factorial);
                break;

            case LinealExampleType.Fibonacci:
                int nFibonacci = 80;     //8 40 80
                for (int i = 1; i <= nFibonacci; i++)
                {
                    long fibonacci = lineal.Fibonacci(i);
                    Console.WriteLine("fibonacci {0} = {1}", i, fibonacci);
                }
                break;

            case LinealExampleType.FibonacciCache:
                for (int i = 1; i <= nFibonacciCache; i++)
                {
                    long fibonacci = lineal.FibonacciCache(i);
                    Console.WriteLine("fibonacci {0} = {1}", i, fibonacci);
                }
                break;
            }
            Console.WriteLine("Time elapsed: {0:0.00} seconds", Math.Round(stopWatch.ElapsedMilliseconds / 1000.0, 2));
            Console.ReadLine();
        }