Created
January 28, 2014 14:08
-
-
Save leonmaia/8668315 to your computer and use it in GitHub Desktop.
Yield
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 object Solve() | |
{ | |
return Fibonnaci().Where(i => i % 2 == 0).Sum(); | |
} | |
private static IEnumerable<int> Fibonnaci() | |
{ | |
int a = 1, | |
b = 2; | |
yield return a; | |
yield return b; | |
while (b < 4000000) | |
{ | |
var auxiliar = b; | |
b += a; | |
a = auxiliar; | |
yield return b; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment