Re: Why is this code causing StackOverflowError?

2010-01-28 Thread Nebojsa Stricevic
Yes, I meant all primes under 200. Also, thanks for the tips, I'll go fix the code right away. Nebojsa -- 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

Re: Why is this code causing StackOverflowError?

2010-01-27 Thread Meikel Brandmeyer
Hi, On Jan 26, 5:38 pm, twitter.com/nfma nuno.filipe.marq...@gmail.com wrote: You can use the sieve of Eratosthenes... This actually is the sieve of Eratosthenes. If one really wants to go out of one's way, one can investigate the sieve of Atkin (or other improved variants) and the the various

Re: Why is this code causing StackOverflowError?

2010-01-27 Thread twitter.com/nfma
hmm... I'm just learning clojure at the moment but by looking at code what I see is: 1 - A collecting parameter called primes 2 - A test to verify if a number is a prime by calculating the reminder of the division with all (or some) of the primes already found 3 - if a number is a prime then its

Re: Why is this code causing StackOverflowError?

2010-01-27 Thread Nebojsa Stricevic
You are right. This isn't exactly sieve of Eratosthenes. My plan was to implement it, but instead, I wrote this, because it was simpler (at least for my knowledge of Clojure). But since it's too slow, I'll transform it to real sieve of Eratosthenes, to check it's performance. On Jan 27, 2:43 pm,

Re: Why is this code causing StackOverflowError?

2010-01-27 Thread Meikel Brandmeyer
Hi, On Jan 27, 2:43 pm, twitter.com/nfma nuno.filipe.marq...@gmail.com wrote: hmm... I'm just learning clojure at the moment but by looking at code what I see is: 1 - A collecting parameter called primes 2 - A test to verify if a number is a prime by calculating the reminder of the

Re: Why is this code causing StackOverflowError?

2010-01-27 Thread Michał Marczyk
Meikel, while the end result is the same, the time complexity of the algorithm is definately not. The exact difference is calculated in Melissa E. O'Neill's paper, The Genuine Sieve of Eratosthenes [1], which also includes some highly performant implementations of incremental SoE-like prime

Re: Why is this code causing StackOverflowError?

2010-01-27 Thread Brenton
I was about to ask the same question on this list about this code adapted from SICP section 3.5.3 pre (defn pi-summands [n] (cons (/ 1.0 n) (lazy-seq (map - (pi-summands (+ n 2)) /pre which causes a stack overflow when I run (nth (pi-summands 1) 1) but it looks like you have

Re: Why is this code causing StackOverflowError?

2010-01-27 Thread Meikel Brandmeyer
Hi, Am 27.01.2010 um 17:57 schrieb Michał Marczyk: while the end result is the same, the time complexity of the algorithm is definately not. The exact difference is calculated in Melissa E. O'Neill's paper, The Genuine Sieve of Eratosthenes. Dang. Details matter. Sincerely Meikel -- You

Re: Why is this code causing StackOverflowError?

2010-01-27 Thread Nebojsa Stricevic
I've transformed algorithm to this: (defn primes-bellow calculates all primes bellow max [max] (loop [numbers (vec (range 2 max)) primes [] last-p 0] (let [p (first (drop-while zero? (drop (dec last-p) numbers)))] (if ( p (. Math

Re: Why is this code causing StackOverflowError?

2010-01-27 Thread Michał Marczyk
2010/1/27 Meikel Brandmeyer m...@kotka.de: Dang. Details matter. :-) 2010/1/27 Nebojsa Stricevic nebojsa.strice...@gmail.com: I've transformed algorithm to this: [ ... elided ... ] And I think, that this is real SoE, and it can calculate sum of first 200 prime numbers in ~35 sec, on

Re: Why is this code causing StackOverflowError?

2010-01-26 Thread Chouser
On Tue, Jan 26, 2010 at 9:17 AM, Nebojsa Stricevic nebojsa.strice...@gmail.com wrote: Greetings, I'm new to Clojure and working my way through Project Euler problems for learning. I wrote function for calculating prime number below some integer value max. But it doesn't work for large

Re: Why is this code causing StackOverflowError?

2010-01-26 Thread Nebojsa Stricevic
Aha... I understand now. Thanks a lot for help. I will try to find other solution. And yes, I'm not looking for too much help. On Jan 26, 3:33 pm, Chouser chou...@gmail.com wrote: On Tue, Jan 26, 2010 at 9:17 AM, Nebojsa Stricevic nebojsa.strice...@gmail.com wrote: Greetings, I'm new to

Re: Why is this code causing StackOverflowError?

2010-01-26 Thread Meikel Brandmeyer
There are a few options, but I suppose you don't want too many hints yet? Oops.. -- 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

Re: Why is this code causing StackOverflowError?

2010-01-26 Thread Meikel Brandmeyer
Hi, On Jan 26, 3:17 pm, Nebojsa Stricevic nebojsa.strice...@gmail.com wrote: I'm new to Clojure and working my way through Project Euler problems for learning. I wrote function for calculating prime number below some integer value max. But it doesn't work for large numbers, causing

Re: Why is this code causing StackOverflowError?

2010-01-26 Thread Meikel Brandmeyer
Hi Chris, On Jan 26, 3:33 pm, Chouser chou...@gmail.com wrote: Of course with this algorithm you *need* filter to be lazy, or you'd never get past the first iteration of the loop. I'm sorry. I have to ask. Why? Sincerely Meikel -- You received this message because you are subscribed to

Re: Why is this code causing StackOverflowError?

2010-01-26 Thread Chouser
On Tue, Jan 26, 2010 at 9:52 AM, Meikel Brandmeyer m...@kotka.de wrote: Hi Chris, On Jan 26, 3:33 pm, Chouser chou...@gmail.com wrote: Of course with this algorithm you *need* filter to be lazy, or you'd never get past the first iteration of the loop. I'm sorry. I have to ask. Why? Hm,

Re: Why is this code causing StackOverflowError?

2010-01-26 Thread Nebojsa Stricevic
Thanks a lot for help. I have much better understanding of laziness now! But I guess I'll need to do some more math research, because both algorithms provided here (my + removed laziness and the one from Meikel) are too slow for calculating all primes below 200. On Jan 26, 4:48 pm, Chouser

Re: Why is this code causing StackOverflowError?

2010-01-26 Thread twitter.com/nfma
You can use the sieve of Eratosthenes... 2010/1/26 Nebojsa Stricevic nebojsa.strice...@gmail.com Thanks a lot for help. I have much better understanding of laziness now! But I guess I'll need to do some more math research, because both algorithms provided here (my + removed laziness and the