RE: Is there an etc. command in perl?

From: Marcos Rebelo (Marcos.Rebelo_at_eurocopter.com)
Date: 02/26/04


To: Jenda@Krynicky.cz, beginners@perl.org
Date: Thu, 26 Feb 2004 15:14:42 +0100


From: Marcos.Rebelo@eurocopter.com
> if you are in school project probably the prof will preffer you to do
> it without using the div or mod operation. Probably he is meening the
> 'Erosthosthenes algorithm'.
>
> Marcos

Please DO NOT TOP POST!

And I don't think the prof is "meening" anything. He might "mean"
something though.

> -----Original Message-----
> From: Joel [mailto:Trag16@hotmail.com]
> Sent: Thursday, February 26, 2004 1:41 PM
> To: perl
> Subject: Re: Is there an etc. command in perl?
>
> Sorry, I should have said. I'm writing a program to find prime
> numbers, and what I want it to do is go from 0 to 200 and divide each
> number by all other numbers. So I want say, 50 to be divided by 1 to
> 50, but to stop when it finds a modulus. If it were a prime number, it
> would be divided by everything between 1 and itself, and no modulus
> would be found. Any suggestions?

1. There is no point dividing by 1.

2. It is enough to test the divisibility by numbers only up to
sqrt(x). Proof is left to the reader as an easy homework.

3. You want to read
        perldoc perlsyn
Look at the loops. In this case you can either use a while() loop
(loop while the divisor is smaller than the sqrt(x) and it does not
divide the tested number) and increment the divisor in the body or
use a for() loop and break out of the loop if you find a divisor.

In both cases you'll have to be able to tell appart the cases when
you found an integer divisor and when you run out of divisors to
check.

Hope I'm making sense. It would be shorter to write the code for you,
but that's exactly what I don't want to do.

Anyway you do want to look up the Erasthotenes sieve algorithm. It's
more efficient.

Jenda

I'm sorry if I offended you. By prof I was willing to say professor.

Marcos



Relevant Pages

  • RE: Is there an etc. command in perl?
    ... but to stop when it finds a modulus. ... In this case you can either use a whileloop ... (loop while the divisor is smaller than the sqrt(x) ... divide the tested number) and increment the divisor in the body or ...
    (perl.beginners)
  • Re: 32bits division
    ... If your DSP doesn't have a hardware division operation, ... Can the operands be scaled so that the divisor can be a power of 2, ... Now I know that this can be done in one cycle by a DSP, ... be faster than a loop. ...
    (comp.dsp)
  • Re: 32bits division
    ... If your DSP doesn't have a hardware division operation, ... Can the operands be scaled so that the divisor can be a power of 2, ... Created a reciprocal lookup table with enough resolution for my ... be faster than a loop. ...
    (comp.dsp)
  • Re: Can PLL Freq Error be zero?
    ... >Oh, so S is the number by which things are divided, the divisor, and has ... Well, I did specify that Somethingorother was the divider in the loop, ... I never use that Laplace stuff. ...
    (sci.electronics.design)
  • Skybucks FastSpawnGeneratorV3 (191 cycles for 100 threads, 10% improvement, code size smaller than J
    ... Let's write an optimized spawn generator to try and beat at least John's ... For example for 100 the divisor starts with 64. ... ;Divide Number of Threads by the divisor. ... ;mov spawn, 0 will be executed for the first thread. ...
    (rec.games.corewar)