Re[2]: [Haskell-cafe]Prime Generator time limit exceeded

2006-11-03 Thread Bulat Ziganshin
Hello alaiyeshi, Thursday, November 2, 2006, 9:26:37 PM, you wrote: I've met replicateM_ for the first time;-) This could be a template for doing online-judge exercises I guess. And it's very useful for newbies like me. make an date for 'interact' :))) -- Best regards, Bulat

Re: Re[2]: [Haskell-cafe]Prime Generator time limit exceeded

2006-11-03 Thread alaiyeshi
Wow! Thank you for your suggestion. But I guess in this problem the first input line and the other are different in their meaning. Thus if I use interact I should parse the input(again), I guess.___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re[4]: [Haskell-cafe]Prime Generator time limit exceeded

2006-11-03 Thread Bulat Ziganshin
Hello alaiyeshi, Friday, November 3, 2006, 4:23:40 PM, you wrote: But I guess in this problem the first input line and the other are different in their meaning. Thus if I use interact I should parse the input(again), I guess. it seems that you don't understand that functional programming

Re: [Haskell-cafe]Prime Generator time limit exceeded

2006-11-02 Thread alaiyeshi
Thank you for replying. Smart method! I've learned much;-) I'll have a try using UArray. Also, I guess my code still waste too much time parsing input (I compiled my code with -prof flag on)... Maybe ByteString may save me (or a smarter brain), What is your opinion about doing faster IO,

Re: [Haskell-cafe]Prime Generator time limit exceeded

2006-11-02 Thread alaiyeshi
Thank you so much! I've met replicateM_ for the first time;-) This could be a template for doing online-judge exercises I guess. And it's very useful for newbies like me. Again many Thanks:-)___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe]Prime Generator time limit exceeded

2006-11-02 Thread Jason Dagit
On 11/2/06, Spencer Janssen [EMAIL PROTECTED] wrote: On Nov 2, 2006, at 8:48 AM, alaiyeshi wrote: Also, I guess my code still waste too much time parsing input (I compiled my code with -prof flag on)... Maybe ByteString may save me (or a smarter brain), What is your opinion about doing

[Haskell-cafe]Prime Generator time limit exceeded

2006-11-01 Thread alaiyeshi
Hi I'm new to Haskell. I found this site on the Haskell wiki https://www.spoj.pl. But I got some trouble on trying to solve the problem titled Prime Generator https://www.spoj.pl/problems/PRIME1. The online-judge system tells me time limit excedded Would you be so kind to tell me how to make

Re: [Haskell-cafe]Prime Generator time limit exceeded

2006-11-01 Thread Dan Weston
I didn't see any other replies and didn't want to leave you hanging, so... Three hints: 1) you are testing every integer = 2 as a divisor when you only need to test prime numbers = floor(sqrt(n)) 2) Since for all n 2, floor(sqrt(n)) n, you can use the very primes you are generating in the

Re: [Haskell-cafe]Prime Generator time limit exceeded

2006-11-01 Thread Dan Weston
Two more hints I used in my code: 5) Except for 2, all primes are odd. Don't bother testing the evens. 6) sqrt(n) is (a little) costly, but I used it in my first solution for clarity. You can also create an infinite list of squares of primes, then trim the list of primes to the length of

Re: [Haskell-cafe]Prime Generator time limit exceeded

2006-11-01 Thread alaiyeshi
Thanks a lot. (you really spoil me;-)) What a stupid mistake I've made!(flush) I'll rewrite my code later. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe]Prime Generator time limit exceeded

2006-11-01 Thread Spencer Janssen
The problem with your approach is the gratuitous use of division, which tends to be very slow. In my solution, I first generate a list of seed primes, all primes less than sqrt 10. Then, for each input m and n, I generate all multiples of the seed primes between m and n. I then