using System;
using System.Linq;
using System.Collections.Generic;
namespace ChooseLesserOfTheTwoEvils
{
public class Program
{
public static void Main()
{
Console.ReadKey();
TestPick8thOnEvilA();
Console.WriteLine("------");
TestPick8thOnEvilB();
Console.WriteLine("------");
Console.ReadKey();
}
static void TestPick8thOnEvilA()
{
Console.WriteLine("TestPick8thOnEvilA");
long eighth = EvilCompanyA.MathProvider.Fibonacci().Skip(7).Take(1).Single();
Console.WriteLine("\nEvil A's 8th fibonacci is {0}", eighth);
}
static void TestPick8thOnEvilB()
{
Console.WriteLine("TestPick8thOnEvilB");
long eighth = EvilCompanyB.MathProvider.Fibonacci().Skip(7).Take(1).Single();
Console.WriteLine("\nEvil B's 8th fibonacci is {0}", eighth);
}
}
}
namespace EvilCompanyA
{
public static class MathProvider
{
public static IEnumerable<long> Fibonacci()
{
IList<long> il = new List<long>();
long a = 0, b = 1;
for (int i = 1; i <= 50; ++i)
{
Console.Write("eager{0} ",i);
il.Add(a);
long n = a;
a += b;
b = n;
}
return il;
}
}
}
namespace EvilCompanyB
{
public static class MathProvider
{
public static IEnumerable<long> Fibonacci()
{
long a = 0, b = 1;
for (int i = 1; i <= 50; ++i)
{
Console.Write("lazy{0} ",i);
yield return a;
long n = a;
a += b;
b = n;
}
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKdXNpbmcgU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWM7CgoKbmFtZXNwYWNlIENob29zZUxlc3Nlck9mVGhlVHdvRXZpbHMKewogICAgcHVibGljIGNsYXNzIFByb2dyYW0KICAgIHsKICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCiAgICAgICAgewoKICAgICAgICAgICAgQ29uc29sZS5SZWFkS2V5KCk7CiAgICAgICAgICAgICAgCiAgICAgICAgICAgIFRlc3RQaWNrOHRoT25FdmlsQSgpOwogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgiLS0tLS0tIik7CiAgICAgICAgIC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IElMaXN0PGxvbmc+IGlsID0gbmV3IExpc3Q8bG9uZz4oKTsKICAKICAgICAgICAgICAgbG9uZyBhID0gMCwgYiA9IDE7CiAgCiAgICAgICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IDUwOyArK2kpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGUoImVhZ2VyezB9ICIsaSk7CiAgICAgICAgICAgICAgICBpbC5BZGQoYSk7CiAgICAgICAgICAgICAgICBsb25nIG4gPSBhOwogICAgICAgICAgICAgICAgYSArPSBiOwogICAgICAgICAgICAgICAgYiA9IG47CiAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAKICAKICAgICAgICAgICAgICAKICAgICAgICAgICAgcmV0dXJuIGlsOwogICAgICAgIH0KICAgIH0KfQogIApuYW1lc3BhY2UgRXZpbENvbXBhbnlCCnsKICAgIHB1YmxpYyBzdGF0aWMgY2xhc3MgTWF0aFByb3ZpZGVyCiAgICB7CiAgICAgICAgcHVibGljIHN0YXRpYyBJRW51bWVyYWJsZTxsb25nPiBGaWJvbmFjY2koKQogICAgICAgIHsKICAgICAgICAgICAgbG9uZyBhID0gMCwgYiA9IDE7CiAgCiAgICAgICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IDUwOyArK2kpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGUoImxhenl7MH0gIixpKTsKICAgICAgICAgICAgICAgIHlpZWxkIHJldHVybiBhOwogICAgICAgICAgICAgICAgbG9uZyBuID0gYTsKICAgICAgICAgICAgICAgIGEgKz0gYjsKICAgICAgICAgICAgICAgIGIgPSBuOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9