Thanks Mark. That is exactly what I ended up doing. Regards, Sunil.
On Sun, Dec 13, 2015 at 8:45 PM, Mark Engelberg <[email protected]> wrote: > Call your memoized function on values 1 .. n-1 first, before calling it on > n. > On Dec 12, 2015 9:45 PM, "Sunil S Nandihalli" <[email protected]> > wrote: > >> a small correction. The function computes the modulo 100000007 of the >> answer and not the answer itself. I ran it in the repl. >> Thanks, >> Sunil. >> >> On Sun, Dec 13, 2015 at 11:08 AM, Sunil S Nandihalli < >> [email protected]> wrote: >> >>> Hi Everybody, >>> I wrote the simple function for computing the number of >>> binary-search-trees that can be formed from a sequence of numbers from 1 to >>> N using memoization. I get a stack-overflow for values more than N of 196. >>> Can anybody help me in figuring out how to fix this? >>> Thanks, >>> Sunil. >>> >>> (defn num-trees [n] >>> (let [modulo 100000007 >>> trunc #(mod % modulo) >>> mult-m (comp trunc *) >>> add-m (comp trunc +) >>> h (fn [mf l] >>> (if (<= l 1) 1 >>> (trunc (reduce add-m 0 >>> (map #(mult-m (mf mf (- l % 1)) (mf mf %)) >>> (range l)))))) >>> mf (memoize h)] >>> (mf mf n))) >>> >>> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to [email protected] >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> [email protected] >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/d/optout. >> > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to [email protected] > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
