Created
October 3, 2013 05:13
-
-
Save aoisensi/6805301 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace Prime | |
{ | |
static class Prime | |
{ | |
static List<ulong> primes = new List<ulong> { (long)2, (long)3 }; | |
public static IEnumerable<ulong> Gets() | |
{ | |
Func<ulong, bool> f = (x) => | |
{ | |
foreach (var prime in primes) | |
if (x % prime > 0) return true; | |
return false; | |
}; | |
foreach (var prime in primes) yield return prime; | |
for (ulong i = primes.Last() + 1; ; i++) | |
{ | |
if(f(i)) | |
{ | |
primes.Add(i); | |
yield return i; | |
}; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment