Again, your input was incredibly beneficial for me. William: Thank you for your comments. As i wrote, eventually I came up with a different solution altogether. To answer your question concerning the previous code:
my initial idea was that since (although unproven) all the different sequences finally converge to the 2^n series, and other sequences in different points (e.g the sequence starting with 5 converges with the one starting at 16), it would be possible to speed up the computation if i would have created a map where past sequences are kept. The idea was that the keys to the map are numbers already calculated and their respective values would be their chain-lengths. That is the reason I wanted to merge the known-map with a (zip)map whose keys are the unknown numbers in the current sequence (kept in the cur-map vector) and values - chain lengths - are those of the number who converged with an already known sequence plus one. This method proved to be consuming too much memory, hence my use a slightly different approach. You have all been very helpful! Cheers, Aviad On 10 February 2010 19:32, Will Hidden <william.hid...@gmail.com> wrote: > Looking at your post I notice some things that strike me as 'odd'. > > The use of (def) in a form that is not a top most form. From my > experience this leads to trouble in the best of times. I think a > better way would be to close over your known-map with a closure. > > While I don't have high hopes that closing over known-map will solve > your out of memory issue it starts, i believe, making the code more > idiomatic. Once that is done I would look at simplifying what update- > known-map and dist functions do. > Its unclear to me why you do a merge of a zipmap of keys to numbers. > Making that clearer might help. I also don't understand your use of a > map to hold the intermediate solutions. My first thought upon reading > the question was a pair of numbers, the first being the number and the > second being the count of the Collatz chain would do the trick, but I > could be missing something. > > (William Hidden) > > > On Feb 10, 10:13 am, Aviad Reich <avi....@gmail.com> wrote: > > thank you. > > I have "-server" and "-Xmx1024m" set in my 'swank-clojure-extra-vm-args, > but > > the problem remains. > > > > Aviad > > > > On 10 February 2010 15:57, Joop Kiefte <iko...@gmail.com> wrote: > > > > > > > > > (Disclaimer: never tried myself) > > >http://hausheer.osola.com/docs/5 > > > > > 2010/2/10 Aviad R <avi....@gmail.com> > > > > > Hi all. > > > > >> I'm trying to learn clojure with the excellent "Programming Clojure" > > >> and projecteuler.net. I am encountering the java heap space error, > and > > >> can't find a workaround, nor a smarter way to write my code (which I > > >> am certain exist). > > > > >> Trying to solve Problem 14 (some spoilers might be ahead, for those > > >> wanting to solve it in the future). > > > > >> The problem and my code are inhttps://pastee.org/hj3sh > > > > >> here is the problem: > > >> I am trying to produce a map of one O(million) key-value pairs using a > > >> recursive function. > > > > >> I can produce a map of the first 100000 numbers in ~1300 msecs, with > > >> 217211 keys. > > >> However, for 150000 and up, I get java.lang.OutOfMemoryError: Java > > >> heap space. > > > > >> so, I assume my code is ok on efficiency, but the recursion is too > > >> deep. > > > > >> am I right? can anyone suggest a way to overcome this problem? > > >> any additional tips and thoughts on the code would be of great help to > > >> me, as I am making my first steps in clojure. > > > > >> Thank you, > > >> Aviad > > > > >> -- > > >> You received this message because you are subscribed to the Google > > >> Groups "Clojure" group. > > >> To post to this group, send email to clojure@googlegroups.com > > >> Note that posts from new members are moderated - please be patient > with > > >> your first post. > > >> To unsubscribe from this group, send email to > > >> clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com> > <clojure%2bunsubscr...@googlegroups.com<clojure%252bunsubscr...@googlegroups.com>> > > >> For more options, visit this group at > > >>http://groups.google.com/group/clojure?hl=en > > > > > -- > > > Communication is essential. So we need decent tools when communication > is > > > lacking, when language capability is hard to acquire... > > > > > -http://esperanto.net -http://esperanto-jongeren.nl > > > > > Linux-user #496644 (http://counter.li.org) - first touch of linux in > 2004 > > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Clojure" group. > > > To post to this group, send email to clojure@googlegroups.com > > > Note that posts from new members are moderated - please be patient with > > > your first post. > > > To unsubscribe from this group, send email to > > > clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com> > <clojure%2bunsubscr...@googlegroups.com<clojure%252bunsubscr...@googlegroups.com>> > > > 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 post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com> > 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 post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en