Sha256: 599b39608216b814882217d97ca2141af525959e41c671db60f6495a64041e01
Contents?: true
Size: 594 Bytes
Versions: 231
Compression:
Stored size: 594 Bytes
Contents
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) { 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
231 entries across 231 versions & 1 rubygems