public void TestMethod_IsPrimeTriplet_197() { const int source = 197; const bool expected = false; bool result = FunctionsPrimes.IsPrimeTriplet(source); Assert.AreEqual(result, expected); }
public void TestMethod_Pi_317() { const int source = 317; const int expected = 66; int result = FunctionsPrimes.Pi(source); Assert.AreEqual(result, expected); }
public void TestMethod_Pi_271() { const int source = 271; const int expected = 58; int result = FunctionsPrimes.Pi(source); Assert.AreEqual(result, expected); }
public void TestMethod_Pi_193() { const int source = 193; const int expected = 44; int result = FunctionsPrimes.Pi(source); Assert.AreEqual(result, expected); }
public void TestMethod_NumberOfPrimeUnder_11() { const int source = 11; int expected = 5; int result = FunctionsPrimes.NumberOfPrimeUnder(source); Assert.AreEqual(result, expected); }
public void TestMethod_Pi_419() { const int source = 419; const int expected = 81; int result = FunctionsPrimes.Pi(source); Assert.AreEqual(result, expected); }
public void TestMethod_Pi_121() { const int source = 121; // 121 = 11 X 11 const int expected = 30; int result = FunctionsPrimes.Pi(source); Assert.AreEqual(result, expected); }
public void TestMethod_NumberOfPrimesByHundred_200() { const int source = 200; Dictionary <int, int> expected = new Dictionary <int, int> { { 100, 25 }, { 200, 21 } }; Dictionary <int, int> result = FunctionsPrimes.NumberOfPrimesByHundred(source); Assert.IsTrue(AssertDictionaryAreEqualed(result, expected)); }
public void TestMethod_GetPrimesBefore_18() { const int source = 18; List <int> expected = new List <int> { 2, 3, 5, 7, 11, 13, 17 }; List <int> result = FunctionsPrimes.GetPrimesBefore(source); Assert.IsTrue(AssertListAreEqualed(result, expected)); }
public void TestMethod_NumberOfPrimesByHundred_900() { const int source = 900; Dictionary <int, int> expected = new Dictionary <int, int> { { 100, 25 }, { 200, 21 }, { 300, 16 }, { 400, 16 }, { 500, 17 }, { 600, 14 }, { 700, 16 }, { 800, 14 }, { 900, 15 } }; Dictionary <int, int> result = FunctionsPrimes.NumberOfPrimesByHundred(source); Assert.IsTrue(AssertDictionaryAreEqualed(result, expected)); }
public void TestMethod_TwinPrime() { const int source = 500; List <int> expected = new List <int> { 2, 11, 17, 41, 71, 101, 107, 197, 227, 281, 311, 431, 461 }; List <int> result = FunctionsPrimes.GetTwinPrimeBefore(source); AssertListAreEqualed(result, expected); }
private static void Main() { Action <string> display = Console.WriteLine; var listOfEcart = FunctionsPrimes.GetEcartBetweenPrimes(2, 200000); foreach (int number in listOfEcart) { Console.Write($"{number} "); } display($"the greatest difference between two primes is : {listOfEcart.Max(n => n)}"); display("Prime numbers by hundred:"); foreach (var kvp in FunctionsPrimes.NumberOfPrimesByHundred(1000)) { display($"{kvp.Key} - {kvp.Value}"); } display(string.Empty); display("Prime numbers by thousand:"); display(string.Empty); foreach (var kvp in FunctionsPrimes.NumberOfPrimesByNthHundred(9000, 1000)) { display($"{kvp.Key} - {kvp.Value}"); } //int count = 0; //for (int i = 3; i <= int.MaxValue - 4; i += 2) //{ // if (FunctionsPrimes.IsPrimeTriplet(i)) // { // count++; // } // display($"Number of prime found: {count} and i: {i}"); //} display("no triplet prime from 3 to 2147483643"); for (BigInteger i = BigInteger.Parse("2147483643"); i <= BigInteger.Parse("2147483699"); i += 2) { BigInteger squareRoot = BigInteger.Pow(i, (int)BigInteger.Log(i)); // wrong square root display($"Big Integer is : {i} and square root is = {squareRoot}"); } display("Pas de prime triplet between 2147483643 and 3147483643"); int count = 0; List <string> result = new List <string>(); for (BigInteger i = BigInteger.Parse("3147483643"); i <= BigInteger.Parse("4147483643"); i += 2) { if (FunctionsPrimes.IsPrimeTriplet(i)) { count++; result.Add(i.ToString()); } display($"Number of prime found: {count} and i = {i}"); } if (result.Count > 0) { foreach (string number in result) { display($"Prime triplet found : {number}"); } } var timestamp = DateTime.Now.ToFileTime(); display($"time stamp using ToFileTime : {timestamp.ToString()}"); string timeStamp = GetTimestamp(DateTime.Now); display($"time stamp yyyymmddhh : {timestamp.ToString()}"); display("Press any key to exit"); Console.ReadKey(); }
public void TestMethod_GetAbsoluteValues() { Dictionary <int, int> source = FunctionsPrimes.GetAbsoluteValues(); }
private static void Main() { Action <string> display = Console.WriteLine; Action <string> displayOnOneLine = Console.Write; display("Demo to use the useful functions DLL"); int[] list = { 1, 2, 3, 1 }; bool result = StringFunc.HasDuplicate(list); display("The array: {1, 2, 3, 1 } has duplicate: " + result); display(string.Empty); displayOnOneLine("Factorial 3 with lowerBound 2 is "); displayOnOneLine(MathFunc.Factorial(3, 2).ToString()); display(string.Empty); displayOnOneLine("IsNumeric of '4' "); displayOnOneLine(StringFunc.IsNumeric("4").ToString()); char[] tmpNull = null; // ReSharper disable once ExpressionIsAlwaysNull string rdnString = StringFunc.GenerateRandomString(tmpNull); display(string.Empty); display("Generation of a random string: " + rdnString); display(string.Empty); display("Manifest of the DLL: " + StringFunc.Manifest()); display(string.Empty); display("Generation of a 10 random filename strings: "); for (int i = 0; i < 10; i++) { rdnString = StringFunc.GenerateRandomString(new[] { ' ' }, true, enumRnd.UpperLowerDigitSpecial, 8, true); display("Random filename: " + rdnString); } string test = Path.GetRandomFileName(); display(string.Empty); display("Generation of a 10 Path.GetRandomFileName: "); for (int i = 0; i < 10; i++) { display("Random filename: " + Path.GetRandomFileName()); } display("Listing all drives:"); List <DriveInfo> allDir = FileFunc.GetAllDrives(new[] { DriveType.CDRom, DriveType.Network, DriveType.Removable }); foreach (var dirName in allDir) { display(dirName.ToString()); } display("displaying all directories:"); var allfilesAndFolders = FileFunc.GetAllDirectories(@"C:\"); var count = 0; foreach (var item in allfilesAndFolders) { display(item); count++; } display(count + " directories were found"); display(""); display("Punctuation characters:"); display("Period: " + Punctuation.Period); display("Backslash: " + Punctuation.Backslash); display("Colon: " + Punctuation.Colon); Livre dune = new Livre { Auteur = "Frank Herbert", Prix = 20.00M, Titre = "Les enfants de Dune" }; // search for twin primes display("Searching for twin primes:"); foreach (int twin in FunctionsPrimes.GetTwinPrimeBefore(500)) { Console.Write($"{twin} "); } Stopwatch chrono2 = new Stopwatch(); chrono2.Start(); var allTwinPrimes = FunctionsPrimes.GetTwinPrimeBefore(int.MaxValue - 2); chrono2.Stop(); TimeSpan ts2 = chrono2.Elapsed; string elapsedTime2 = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts2.Hours, ts2.Minutes, ts2.Seconds, ts2.Milliseconds / 10); try { using (StreamWriter sw2 = new StreamWriter("twinPrimes.txt")) { sw2.WriteLine(string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts2.Hours, ts2.Minutes, ts2.Seconds, ts2.Milliseconds / 10)); sw2.WriteLine("RunTime with chrono: " + elapsedTime2); foreach (int twin in allTwinPrimes) { sw2.WriteLine(twin); } } } catch (Exception) { display("There were an error while trying to write to a file all twin primes before int.max"); } // calculating the time necessary to go through all numbers until int.max about billions var startTime = DateTime.Now; Stopwatch chrono = new Stopwatch(); chrono.Start(); for (int i = 0; i < int.MaxValue; i++) { } var endTime = DateTime.Now; chrono.Stop(); TimeSpan ts = chrono.Elapsed; string elapsedTime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("RunTime " + elapsedTime); using (StreamWriter sw = new StreamWriter("timeToIntMax.txt")) { sw.WriteLine($"start time is {startTime}"); sw.WriteLine($"End time is {endTime}"); sw.WriteLine(string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)); sw.WriteLine("RunTime with chrono: " + elapsedTime); } //for (int i = 0; i < FunctionsPrimes.GetTwinPrimeBefore(500).Count; i +=2) //{ // Console.Write($"{twin} "); //} /* twin primes * 2-3 * 11-13 * 17-19 * 41-43 * 71-73 * 101-103 * 107-109 * 197-199 * 227-229 * 281-283 * 311-313 * 431-433 * 461-463 * */ display(""); //display("primes:"); //for (int i = 3; i < 500; i = i + 2) //{ // if (FunctionsMath.IsPrime(i)) // { // Console.Write($"{i} "); // } //} display(""); display("Press any key to exit:"); Console.ReadKey(); }