You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingSystem;usingSystem.Collections.Generic;usingstaticMemes;varfib=Memoize<int,int>((n,fib)=>nswitch{<=1=>1,varm=>fib(n-1)+fib(n-2)});Console.WriteLine(fib(40));publicstaticclassMemes{publicstaticFunc<TIn,TOut>Memoize<TIn,TOut>(Func<TIn,Func<TIn,TOut>,TOut>func){vardic=newDictionary<TIn,TOut>();Func<TIn,TOut>rec=null;rec= tin =>{if(dic.TryGetValue(tin,outvarres))returnres;res=func(tin,rec);dic[tin]=res;returnres;};returnrec;}}
Activity
WhiteBlackGoose commentedon Jun 18, 2022
Re-consideration with #25: make
Where
mrecis a memoizing recursor