5 ms·
Naive fibonacci is a much more interesting example for memoize than factorial: fib = +lambda {|n| return 1 if n <= 1; fib[n-2] + fib[n-1]}
by teoryn 15y ago
Naive fibonacci is a much more interesting example for memoize than factorial:
fib = +lambda {|n| return 1 if n <= 1; fib[n-2] + fib[n-1]}
- irahul 15y agoYes. I added that to tests and README. Except that I have fib = +lambda {|n| return n if n <= 1; fib[n-1] + fib[n-1] } My fibonacci is 0, 1, 1, 2, 3.. and yours is 1, 1, 2, 3... but doesn't make a difference as far as example goes.