Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: Prime Number Finder

by Anonymous Monk
on May 04, 2002 at 18:08 UTC ( #164038=note: print w/replies, xml ) Need Help??


in reply to Re: Prime Number Finder
in thread Prime Number Finder

Isn't the math wrong here? I get false primes with this.

Replies are listed 'Best First'.
Re: Re: Re: Prime Number Finder
by LanceDeeply (Chaplain) on Jul 17, 2002 at 19:58 UTC
    nope! they all look prime to me!
    i like it, i'm gonna use it to explain programming loops to a mathmatician friend. i took the liberty to re-arrange a touch...
    sub isPrime { my $number = shift; my $sqrt = sqrt $number; my $d = 2; while (1) { return 0 if ( $number % $d == 0 ); return 1 if ( $d > $sqrt ); $d++; } }
Re^3: Prime Number Finder
by Anonymous Monk on Apr 16, 2013 at 20:44 UTC
    In fact, you're right, because numbers which only can be devided in 1, themselves and their square root will be marked as prime in this way. make the < into a <= and it is solved.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://164038]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2016-09-26 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (489 votes). Check out past polls.