Skip to content

Instantly share code, notes, and snippets.

@ungood
Created July 10, 2012 19:47
Show Gist options
  • Save ungood/3085778 to your computer and use it in GitHub Desktop.
Save ungood/3085778 to your computer and use it in GitHub Desktop.
LINQ Mandelbrot Calculation
public class GenerateAndCountCalculator : IMandelbrotCalculator
{
public int CalculatePoint(Complex c, int maxIterations)
{
return Generate(Complex.Zero, z => (z * z) + c)
.TakeWhile(z => z.Magnitude <= 2)
.Take(maxIterations)
.Count();
}
public static IEnumerable<T> Generate<T>(T seed, Func<T, T> generator)
{
while (true)
{
seed = generator(seed);
yield return seed;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment