Created
August 10, 2012 09:39
-
-
Save renestein/3312979 to your computer and use it in GitHub Desktop.
FibonacciKata.cs
This file contains 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
using System; | |
using System.Reactive.Linq; | |
namespace FibonacciKata | |
{ | |
class Program | |
{ | |
public const int LIMIT = 4000000; | |
static void Main(string[] args) | |
{ | |
Observable.Generate(new | |
{ | |
Previous = 1, | |
Current = 2, | |
Total = 0 | |
}, | |
state => state.Previous <= LIMIT, | |
state => new | |
{ | |
Previous = state.Current, | |
Current = state.Previous + state.Current, | |
Total = state.Total + (state.Current % 2 == 0 ? state.Current : 0) | |
}, | |
state => state.Total) | |
.TakeLast(1) | |
.Subscribe(Console.WriteLine); | |
Console.ReadLine(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment