in reply to Re^8: Number functions.. primes (ugly code runs faster)
in thread Number functions I have lying around

Here are some of the problems.

Like with many car shows my hubby watches where the show glosses over a lot, it is like you took the logo off the car, trashed the car, and put the logo on another car. I still don't know what is so wrong with the original car (function) that the only thing worth saving was the logo (function name). So take one part out at a time, explain why it is broken, then install the new part telling the audience why the new part is better. Pretty please?

No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

Replies are listed 'Best First'.
Re^10: Number functions.. primes (ugly code runs faster)
by trippledubs (Deacon) on Apr 08, 2015 at 20:09 UTC
    I also struggle with Math!!

    A number cannot be prime if it is a perfect square. 16 is perfect square of 4. 16 not prime.

    A number is only prime if two other integers cannot be multiplied together to equal that number.

    Take 37, sqrt = 6.08

    • So as you iterate over the numbers..
    • 37 % 2 == 0, nope. Another way to say is that 2 * something = 37 with no remainder
    • 37 % 3 == 0, nope. Another way to say is that 3 * something = 37 with no remainder
    • 37 % 4 == 0, nope. Another way to say is that 4 * something = 37 with no remainder
    • 37 % 5 == 0, nope. Another way to say is that 5 * something = 37 with no remainder
    • 37 % 6 == 0, nope. Another way to say is that 6 * something = 37 with no remainder

    Our next number would be 7. But we know that 6.08 times any number smaller than 6.08 is < 37 and 6.08 times any number larger than 6.08 is > 37

    So, in our next iteration, 7 * something = 37 with no remainder, for that something to multiply 7 and make 37, would *have* to be smaller than 6.08, and we already tested all those.

    Does that sound right?
Re^10: Number functions.. primes (ugly code runs faster)
by choroba (Cardinal) on Apr 09, 2015 at 08:47 UTC