static void Main() { PrimesList Primes = new PrimesList(); Write("Press enter to exit..."); Read(); }
public void Reseed() { yShift = PrimesList.Choose0(); seed1 = PrimesList.Choose1(); seed2 = PrimesList.Choose2(); seed3 = PrimesList.Choose3(); }
// Returns the time it takes to initializes various sizes of PrimesList static void TimePrimeListInitialization(int Trials = 5) { Stopwatch Stopwatch = new Stopwatch(); for (int MaxNum = 10 * 1000; MaxNum <= 10 * 1000 * 1000; MaxNum *= 10) { long TotalTime = 0; for (int i = 0; i < Trials; i++) { Stopwatch.Start(); PrimesList Primes = new PrimesList(MaxNum); TotalTime += Stopwatch.ElapsedMilliseconds; Stopwatch.Reset(); } WriteLine("Generating primes until 10^{0}, in one go, took {1} milliseconds", Log(MaxNum, 10), TotalTime / Trials); } }
// Tests that the list contains all the primes between Min and Max inclusively // Uses FileDir as reference static void TestContainsPrimes(int Min, int Max, string FileDir) { int WrongPrimes = 0; PrimesList Primes = new PrimesList(Max); WriteLine("Generated primes."); foreach (string Line in File.ReadAllLines(FileDir)) { int Prime = Int32.Parse(Line); if (!Primes.Contains(Prime)) { WrongPrimes++; WriteLine("{0} is not contained in the list!", Prime); } } WriteLine("Found {0} wrong primes.", WrongPrimes); }
// Returns the time it takes to check, one at a time, if the numbers under a certain limit are prime static void TimePrimeChecking(int Trials = 5) { long TotalTime = 0; int Limit = 10 * 1000 * 1000; Stopwatch Stopwatch = new Stopwatch(); for (int i = 0; i < Trials; i++) { Stopwatch.Start(); PrimesList Primes = new PrimesList(); for (int j = 0; j < Limit; j++) { Primes.Contains(j); } TotalTime += Stopwatch.ElapsedMilliseconds; Stopwatch.Reset(); } WriteLine("Checking numbers under 10^{0} for primes, one at a time, took {1} milliseconds", Log(Limit, 10), TotalTime / Trials); }
static void Main() { int UpRight = 1; int UpLeft = 1; int DownLeft = 1; // DownRight is not needed since it contains odd square, none of which can be prime int PrimesCount = 0; PrimesList Primes = new PrimesList(); int i = 0; do { UpRight += 8 * i + 2; UpLeft += 8 * i + 4; DownLeft += 8 * i + 6; // Oh! look at those patterns, isn't the universe beautiful? if (Primes.Contains(UpRight)) { PrimesCount++; } if (Primes.Contains(UpLeft)) { PrimesCount++; } if (Primes.Contains(DownLeft)) { PrimesCount++; } WriteLine(DownLeft); i++; WriteLine(PrimesCount + " / " + (4 * i + 1) + " = " + (double)PrimesCount / (4 * i + 1)); } while ((double)PrimesCount / (4 * i + 1) >= 0.1); WriteLine("Side length is {0}", 2 * i + 1); WriteLine("i is {0}", i); WriteLine("Press enter to exit..."); Read(); }
static void Main() { int[] Primes = new PrimesList(10 * 1000).GetPrimes(10 * 1000, 1000).ToArray <int>(); for (int i = 0; i < Primes.Length; i++) { int Prime0 = Primes[i]; for (int j = i + 1; j < Primes.Length; j++) { int Prime1 = Primes[j]; for (int k = j + 1; k < Primes.Length; k++) { int Prime2 = Primes[k]; if (Prime0 != Prime1 && Prime1 != Prime2 && Prime1 - Prime0 == Prime2 - Prime1 && ArePermutations(Prime0, Prime1, Prime2)) { WriteLine("{0}, {1}, and {2}", Prime0, Prime1, Prime2); } } } } Write("Press enter to exit..."); Read(); }
public void Init() { primes = new PrimesSieve(10000); }