Sha256: 29d1b2647f08ed837f0a0cae85134e0b25c1d7c0794b0718886d2007b5381b57
Contents?: true
Size: 718 Bytes
Versions: 165
Compression:
Stored size: 718 Bytes
Contents
using System; using System.Collections.Generic; using System.Linq; public class Sieve { public static int[] Primes(int limit) { return InitializePrimes(limit); } private static int[] InitializePrimes(int limit) { if (limit < 2) { throw new ArgumentOutOfRangeException(nameof(limit)); } var candidates = new Queue<int>(Enumerable.Range(2, limit - 1)); var primes = new List<int>(); do { var prime = candidates.Dequeue(); primes.Add(prime); candidates = new Queue<int>(candidates.Where(x => x % prime != 0)); } while (candidates.Any()); return primes.ToArray(); } }
Version data entries
165 entries across 165 versions & 1 rubygems