Ejemplo n.º 1
0
        public static void ExecuteBinaryAndSieve()
        {
            BinarySieve     sieve = new BinarySieve();
            IMenuController alg   = new Algorythms() as IMenuController;

            int maxPrimeSetSize;

            if (!int.TryParse(Console.ReadLine(), out maxPrimeSetSize))
            {
                Console.WriteLine("Not a number. Bhye, Bhye!");
                Console.ReadLine();

                alg.MainMenu();
            }
            if (maxPrimeSetSize > 500000)
            {
                Console.WriteLine("The number was larger than 500.000. We don't have all day here...");
                Console.ReadLine();
                return;
            }
            DateTime startTime = DateTime.Now;

            sieve.BinarySearch(sieve.SieveOfEratostenes(maxPrimeSetSize));
            DateTime endTime   = DateTime.Now;
            string   deltaTime = (endTime - startTime).TotalSeconds.ToString();

            Console.WriteLine($"\nExecution time was {deltaTime} seconds");
            Console.ReadLine();

            alg.MainMenu();
        }
Ejemplo n.º 2
0
        public static void Backtracking()
        {
            //TODO: Add input for number of rows and collumns

            EightQueenProblem eightQueenProblem = new EightQueenProblem(8);

            eightQueenProblem.Initialize();
            eightQueenProblem.DisplaySolution();
            Console.ReadLine();

            IMenuController alg = new Algorythms() as IMenuController;

            alg.MainMenu();
        }
        public static void ExecuteMultiplyMatrices()
        {
            // Set up matrices. Use small values to better view
            // result matrix. Increase the counts to see greater
            // speedup in the parallel loop vs. the sequential loop.
            int colCount  = 180;
            int rowCount  = 2000;
            int colCount2 = 270;

            double[,] m1     = InitializeMatrix(rowCount, colCount);
            double[,] m2     = InitializeMatrix(colCount, colCount2);
            double[,] result = new double[rowCount, colCount2];

            // First do the sequential version.
            Console.Error.WriteLine("Executing sequential loop...");
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            MultiplyMatricesSequential(m1, m2, result);
            stopwatch.Stop();
            Console.Error.WriteLine("Sequential loop time in milliseconds: {0}",
                                    stopwatch.ElapsedMilliseconds);

            // For the skeptics.
            OfferToPrint(rowCount, colCount2, result);

            // Reset timer and results matrix.
            stopwatch.Reset();
            result = new double[rowCount, colCount2];

            // Do the parallel loop.
            Console.Error.WriteLine("Executing parallel loop...");
            stopwatch.Start();
            MultiplyMatricesParallel(m1, m2, result);
            stopwatch.Stop();
            Console.Error.WriteLine("Parallel loop time in milliseconds: {0}",
                                    stopwatch.ElapsedMilliseconds);
            OfferToPrint(rowCount, colCount2, result);

            // Keep the console window open in debug mode.
            Console.Error.WriteLine("Press any key to exit.");
            Console.ReadKey();

            IMenuController alg = new Algorythms() as IMenuController;

            alg.MainMenu();
        }
Ejemplo n.º 4
0
        public static void Initialize()
        {
            BuySellGold buySellGold = new BuySellGold();

            //int[] pricesGroup = new int[10000];
            //Random rnd = new Random();

            //for (int i = 0; i < pricesGroup.Length; i++)
            //{
            //    pricesGroup[i] = rnd.Next(rnd.Next(0, 100000), 10000000);
            //}

            int[] pricesGroup = new int[] { 200, 187, 167, 133, 121, 100, 70, 55, 23, 1 };

            buySellGold.bestDays = buySellGold.FindMaxOrMinDifference(pricesGroup, pricesGroup.Length);

            buySellGold.WriteResults();

            IMenuController alg = new Algorythms() as IMenuController;

            alg.MainMenu();
        }
        public static void Meh()
        {
            IMenuController alg = new Algorythms() as IMenuController;

            alg.MainMenu();
        }