Skip to content

Instantly share code, notes, and snippets.

@einarwh
Created October 5, 2011 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save einarwh/1263365 to your computer and use it in GitHub Desktop.
Save einarwh/1263365 to your computer and use it in GitHub Desktop.
Infinite sequence of prime numbers that uses wheel factorization.
public class WheelPrimeSequence : IEnumerable<int>
{
public IEnumerator<int> GetEnumerator()
{
yield return 2;
yield return 3;
yield return 5;
var e = new WheelPrimeEnumerator();
while (e.MoveNext())
{
yield return e.Current;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment