Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

(ichimunki) Re: Prime Number Finder

by ichimunki (Priest)
on Feb 07, 2002 at 19:59 UTC ( #143959=note: print w/replies, xml ) Need Help??


in reply to Prime Number Finder

You may as well write
for($i=$o; $i<=$e; $i++){
as
print "2 is prime\n" if $o == 2; $o++ if $o % 2; for my $i ( $i=$o; $i<=$e; $i+=2 ){
That way you start on an odd number and account for the only even number which is prime. There is no need to check even numbers after 2.

Replies are listed 'Best First'.
Re^2: Prime Number Finder
by dragonchild (Archbishop) on Nov 11, 2005 at 23:07 UTC
    $o++ if $o % 2 == 0;

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://143959]
help
Chatterbox?
[LanX]: ... and it might be your last chance ... I heard Perl is dead! OO
[marto]: someone read the post about search.cpan being shut down, and commented "It's going to be awhile before I learn to not type "cpan.org" into my address bar."
[Discipulus]: ;=) the same here: S + ENTER is my way to cpan in browser

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2018-06-20 09:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (116 votes). Check out past polls.

    Notices?