From: "Brian Schröder" Date: 2004-11-15T04:54:34+09:00 Subject: Re: [QUIZ] Countdown (#7) [Solution] On Mon, 15 Nov 2004 04:08:22 +0900 Dennis Ranke wrote: > Brian Schr�der wrote: > > Hello Group, > > > > This was quite an interesting quiz. I tried different solutions of varying > > complexity, but it turned out that the simplest approach worked best. > > That's a nice solution, but reading through the code I have one question > regarding the memoized version: > > > def Integral.each_term_over(source, memo = {}, &block) > > return memo[source] if memo[source] > > Shouldn't each_term_over call the block for each term when the terms for > this set of sources was already generated before as well? Now it just > returns the terms but each_term_over itself just ignore the return > value. But maybe I just didn't understand the code correctly, after all, > it appears to work well (although using too much memory on my machine ;) > each_term_over calls the block once for each unique term it generates. When a set of terms is already memoized, the block has been called for each of the terms in the set, so it is not neccessary to call it again. This additionally speeds up the process. Regards, Brian -- Brian Schr�der http://www.brian-schroeder.de/