• MadAdmin (6/24/2016)


    drew.allen (6/24/2016)


    I think that Luis' solution will perform faster than any looping solution, especially once the square root short circuit is added.

    Drew

    surely the cte is faster, but they do different things. Luis solution returns whether a given number is prime whereas mine returns a list of about 79000 prime numbers from the first million integers.

    Though my example is probably beyond the pale as my project was to see how long it took to build the list, which in 1997 took an age and a day with C, so the Math had to be clearly understood to make it work quickly by working out shortcuts.

    In that case, Eirikur's code would do the same thing.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2