using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Fib
{
class Program
{
static void Main(string[] args)
{
Debug.WriteLine(EvenFibLessThan(40000));
}
static int EvenFibLessThan(int maxFibNumber)
{
int ret = 0;
int lastEven = 0;
foreach (var i in fibEnumerator())
{
Debug.WriteLine(i);
if (i % 2 == 0)
{
if (i > maxFibNumber)
return lastEven;
lastEven = i;
}
}
return ret;
}
static IEnumerable<int> fibEnumerator()
{
int last = 1;
yield return last;
int current = 1;
yield return current;
while (true)
{
int next = last + current;
last = current;
current = next;
yield return current;
}
}
}
}