I'm working one of the Euler project problems, which asks for the first triangle number with more than 500 divisors. I thought it might be fun to use lazy sequences, and tried two approaches. One worked, the other blew the stack. I'm trying to understand why the second approach fails.
Here's the successful approach. (defn tri [n] (* n (inc n) 1/2)) (defn triangle-numbers [] (map tri (iterate inc 1))) (take 1 (filter #(> (count-divisors %) 500) (triangle-numbers))) I have omitted the definition of count-divisors for the sake of brevity. The failing approach is the same, except for an alternative definition of the triangle numbers: (defn triangle-numbers [] (lazy-cat [1] (map + (iterate inc 2) (triangle-numbers)))) This second approach dies with a stack overflow. Can anyone shed some light on why? Thank you. David Cabana --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---