C#, Interactive Extensions でフィボナッチ数列のn番目の項を求める

Ix便利.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Fibonacci
{
    class Program
    {
        static void Main(string[] args)
        {
            var fib = EnumerableEx.Generate(new { Z1 = BigInteger.One, Z2 = BigInteger.Zero },
                    _ => true, z => new { Z1 = z.Z1 + z.Z2, Z2 = z.Z1 }, z => z.Z1)
                .StartWith(0)
                .Memoize();

            var sw = new Stopwatch();

            while (true)
            {
                int num;
                if (int.TryParse(Console.ReadLine(), out num))
                {
                    sw.Restart();
                    var result = fib.Skip(num).First();
                    sw.Stop();

                    Console.WriteLine($"[{num}] = {result}, ({sw.ElapsedMilliseconds}[ms])");
                }
            }
        }
    }
}