Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: is it prime?

by JavaFan (Canon)
on May 06, 2012 at 05:39 UTC ( #969111=note: print w/replies, xml ) Need Help??


in reply to is it prime?

It cannot be correct. Have you actually tried this? Considering that any number is divisible by 1, isPrime will return 1 for each number. A fix is easy, have $i start at 2.

But then you are still far from being efficient. There's no need to loop to $num/2, you can stop at sqrt($num). There's no need to test even numbers (except 2). And there's no need to continue once you've found a divisor.

Replies are listed 'Best First'.
Re^2: is it prime?
by Anonymous Monk on May 06, 2012 at 05:44 UTC
    i did test it, you are correct it is incorrect i was hoping for a fix (hence why i posted) thanks for the help
      also you are right again i dont need a loop hell knows why i was using one sinse im only sending 1 arg (digit) at a time to the sub routine :/
        no.. above was wrong.. jeez now i dont know what im talking about haha this isnt going good :/ not slept all night is my excuse!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969111]
help
Chatterbox?
[ambrus]: Corion: well Prima::Object says something like that the cleanup method will send an onDestory message and that you can't get more messages after cleanup, or something.
[Corion]: ambrus: Yeah - I don't think the deep source dive will be necessary if things are implemented as simple as they could be :)) And hopefully I won't need (more) timely object destruction. I can update the screen at 60Hz and hopefully even do HTTP ...
[Corion]: ... transfers in the background. Now that I think about it, this maybe even means that I can run the OpenGL filters on Youtube input :)
[ambrus]: Corion: I mentioned that the unix event loop of Prima always wakes up at least once every 0.2 seconds. Have you found out whether the win32 event loop of Prima does that too?
[Corion]: ambrus: Hmm - I would assume that the onDestroy message is sent from the destructor and doesn't go through the messageloop, but maybe it is sent when a window gets destroyed but all components are still alive...
[ambrus]: Corion: partly deep source dive, partly just conservative coding even if it adds an overhead.
[Corion]: ambrus: Hmm - no, I haven't looked at wakeup intervals ... I wonder why it should want to wakeup periodically because it gets a lot of messages from the Windows message loop (on Windows obviously)
[ambrus]: (Alternately a deep source dive and then rewrite that event loop to make it better, and then as a bonus you get an idle method.)
[ambrus]: The 0.2 seconds wakeup is likely a workaround for some bug, but I can't guess what bug that is.
[ambrus]: It's been there since Prima 1.00 iirc

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2016-12-09 10:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (150 votes). Check out past polls.