Skip to content

Instantly share code, notes, and snippets.

@renestein
Created August 10, 2012 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renestein/3312979 to your computer and use it in GitHub Desktop.
Save renestein/3312979 to your computer and use it in GitHub Desktop.
FibonacciKata.cs
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