Hacker News new | ask | show | jobs
by kevinastock 5392 days 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]}
1 comments

Yes. 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.