Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

Y Fibonnoci

//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        delegate T id<T>(T arg0);
    
        static id<T> Y<T>(id<id<T>> f)
        {
            //Y f = f ( Y f )
            return x => f(Y(f))(x);
        }
        
        static id<id<T>> _<T>(id<id<T>> f) { return f; }
        
        public static void Main(string[] args)
        {
            var fib = _<int>(f => n => n < 3 ? n : f(n - 1) + f(n - 2));
            Console.WriteLine(Y(fib)(5));
        }
    }
}
 run  | edit  | history  | help 0