user> (defn cseq [n] (if (= 1 n) [1] (lazy-seq (cons n (cseq (if (even? n) (/ n 2) (+ (* 3 n) 1 ))))))) #'user/cseq user> (count (apply max-key count (map cseq (range 1 1000000)))) 525
user> (first (apply max-key count (map cseq (range 1 1000000)))) 837799 The solution is 837799, but the longest sequence is 525. My primary question remain (towards the non-lazy version). Why does this fail btw? (def a (apply max-key count (map cseq (range 1 1000000)))) *Heap error* Thanks. 2011/1/19 Miki <miki.teb...@gmail.com> > > (defn cseq [n] >> (if (= 1 n) >> [1] >> (cons n (cseq (if (even? n) >> (/ n 2) >> (+ (* 3 n) 1 )))))) >> >> (apply max-key count (map cseq (range 1 1000000))) >> >> Gives a heap error. >> cseq is at most 525 elements long. >> > The solution is much more than 525 (> 800000). Note that you're probably > computing the same thing over and over again so "memoize" > can come very handy here. > > -- > 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