Aviad,

Welcome to Clojure.

I don't want to tell you how to solve it. That's all part of the fun.
But my hint to you would be that you don't need to keep all 1 million
lists in memory. In fact, you should be able to solve this problem by
only keeping three numbers in memory at any one time: The number that
has produced the longest chain, the size of the longest chain and the
size of the current chain you are working on.

Also, as I was recently reminded by this group, it is never a good
idea to use def within a function. This problem can be solved using
only pure functions.

Good luck,
Brenton

On Feb 10, 7: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>
> >> 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>
> > 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

Reply via email to