A circular sieve of eratosthenes to visualize prime numbers
sievesofchaos.com
sievesofchaos.com
timing_array = Hash.new
for q in 0..6
max_n = 10**q
prime_array = Array.new
for z in 0..max_n
prime_array[z] = 0
end
for i in 2..max_n
a = max_n / i
for j in 1..a
prime_array[j*i] += 1 unless j*i > max_n
end
end
puts "prime numbers to #{max_n}"
prime_array.each_with_index {|num,v| puts "#{v}" unless num > 1}
timing_array[max_n] = Time.now
endputs "and the resultz"
puts timing_array
1000000 Sun Dec 13 20:33:05 -0500 2009
100000 Sun Dec 13 20:32:34 -0500 2009
10000 Sun Dec 13 20:32:31 -0500 2009
1000 Sun Dec 13 20:32:31 -0500 2009
100 Sun Dec 13 20:32:31 -0500 2009
On Ubuntu, if you install bsdgames, "primes" can generate a list of primes up to (checks) 2^32 (4.29 billion & change).
djb's primegen - http://cr.yp.to/primegen.html - goes up to 1000000000000000 (10^15).