Prime Numbers as a SQL Query
This isn't a Sieve of Eratosthenes algorithm, but it's too good not to share it.
select r
from (
select rownum+1 r from dual connect by rownum < 10000
)
where
r=2
or 0 not in(
select mod(r,rownum+1) from dual
connect by rownum<sqrt(r)
)
This is an Oracle query that will generate all of the primes up to 10,000. The query is not even close to fast, but I think it's kind of funny. It's just your typical everyday brute force method of calculating prime numbers.
Comments(0)