/// <summary> /// Method that displays the found primes /// </summary> /// <param name="highest">Largest number that primes were calculated for</param> private static void ShowPrimes(ulong highest) { Console.WriteLine(); if (IOFunctions.GetBoolFromUser("Would you like to see the primes? ")) { int highestNumberLen = highest.ToString().Length; int resultsPerRow = (Console.WindowWidth - 1) / (highestNumberLen + 1); string format = "{0," + highestNumberLen.ToString() + "} "; // Use a sorted set to combine all of the lists of primes SortedSet <ulong> sortedPrimes = new SortedSet <ulong>(); foreach (int key in m_Primes.Keys) { sortedPrimes.UnionWith(m_Primes[key]); m_Primes[key].Clear(); } // Print the primes into columns int col = 0; foreach (ulong prime in sortedPrimes) { Console.Write(format, prime); col++; if (col >= resultsPerRow) { Console.WriteLine(); col = 0; } } } }
/// <summary> /// Shows the statistics for the calculations /// </summary> private static void ShowStats() { Console.WriteLine(); if (IOFunctions.GetBoolFromUser("Would you like to see the statistics? ")) { // Output results Console.WriteLine(); int primesFound = 0; foreach (int key in m_Primes.Keys) { Console.WriteLine("Thread {0} found {1:N0} primes.", key, m_Primes[key].Count); primesFound += m_Primes[key].Count; } Console.WriteLine("Total: {0:N0} primes.", primesFound); } }