Project Euler problem in clojure

2013-06-20 Thread John Holland
I'm working on problems at projecteuler.net in Clojure. There is a particular problem that my code doesn't seem to work for. The problem is: == The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 +

Re: Project Euler problem in clojure

2013-06-20 Thread John Holland
OK, with a coding improvement (defn factors-sqrt [n] (filter #(= 0 (mod n %)) (range 1 (+ 1 (Math/sqrt n ) (defn num-of-factors [n] (* 2 (count (factors-sqrt n it works for 499. (Idea being factors come in pairs, each factor sqrt(x) corresponds to one sqrt(x)) Was it just running

Re: Project Euler problem in clojure

2013-06-20 Thread Meikel Brandmeyer (kotarak)
Hi, Am Donnerstag, 20. Juni 2013 15:19:40 UTC+2 schrieb John Holland: (defn triangle [n] (reduce + (range n))) (def lazytri (lazy-seq (map triangle (range Some quick idea: here is a major difference in your clojure and your java implementation. You always recompute the whole sum for

Re: Project Euler problem in clojure

2013-06-20 Thread Alan Malloy
More importantly than any of these things, he is hanging onto the head of a very, very large sequence with (def lazytri (map triangle (range))). This will lead to serious memory pressure, and perhaps eventually a slowdown as this sequence takes up all the memory in his app and the GC strains to