Skip to content

Instantly share code, notes, and snippets.

@aoisensi
Created October 3, 2013 05:13
Show Gist options
  • Save aoisensi/6805301 to your computer and use it in GitHub Desktop.
Save aoisensi/6805301 to your computer and use it in GitHub Desktop.
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