Re: LF: PRIME NUMBERS!


[Prev][Next][Index][Thread]

Re: LF: PRIME NUMBERS!



On Thu, 12 Dec 1996, Kevin T. Huber wrote:

> 
> Of course if you did a simple test for division by 2 and incremented c by 2
> you would double the performance.  You also recalculate the square root of
> x every iteration when you could have assigned it to a variable.  Also it

actually, you're wrong.   the first test checks for 2 as a factor, so it
DOES test for division by two.  if you incremented c by 2 after the first
test, that might help, yes.  if you'd paid a little more attention, you'd
notice that x changes its value, so using a precalculated variable
wouldn't work.

> appears from inspection that the routine won't work for repeated factors
> (i.e. 8=2*2*2) since you don't reinitialize c.  In other words, this

wrong again.  it loops for the same value of c, so it would list, 2, find
2 again, find 2 again, and then stop.

> routine is worthless.

sorry, you lose.  pay a little bit better attention to what you're talking
about next time you critique someone's code.  I don't enjoy material I
present being called worthless by someone that can't interpret code
correctly.

>  > TI-82 programming:
>  > 
>  > Input x
>  > 2->c

c starts as two, so the first check is a divide by two

>  > Lbl 1
>  > If c> sqrt(x)  //sqrt(n) -- take the square root
>  > Goto 2
>  > If fpart (x/c)=3D0 then x/c -> x // fpart means the part after the decimal

x changes its value in the previous line.

>  > Disp c // display the value of c
>  > goto 1

c is still its current value when the program loops to check for that
number again.

>  > end // ends if-then statement
>  > c+1 -> c
>  > goto 1 //if if statement was false, increment c and goto 1
>  > lbl 2
>  > if x>1 disp x
>  > 
>  > :end program

again, check the code you're reading more carefully before you start
criticizing.

Jonathan Dickmann
email:jdickman@rhf.bradley.edu


Follow-Ups: References: