On 5 Sep 2002, at 4:45, Bret Jolly wrote: > > (...) You could try extending > > that, or you could have a look at Robert Feldt's memoize package: > > I've been having a tough time getting this to work. Can someone > tell me what I'm doing wrong? Here is an attempt to memoize a clumsy > recursion that screams for memoization (a recursive calculation of the > binomial coefficient "n choose k"). > > (...) Hi Bret, in the memoize docs it says that only functions not depending on internal state can be memoized, in other words the function result should only depend on the function arguments. Clearly 15.choose 7 is different from 10.choose 7 although the arg list is the same. If you change the implementation to something like class Integer def choose(k) choose2(self,k) end private def choose2(n,k) if (k==0 or k==n) 1 else choose2(n-1,k) + choose2(n-1,k-1) end end memoize :choose2 end it should work as you expected. Regards, Pit