Created
July 10, 2012 19:47
-
-
Save ungood/3085778 to your computer and use it in GitHub Desktop.
LINQ Mandelbrot Calculation
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
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