Hacker News new | past | comments | ask | show | jobs | submit login
A circular sieve of eratosthenes to visualize prime numbers (sievesofchaos.com)
44 points by nobody_nowhere on Dec 13, 2009 | hide | past | favorite | 6 comments



After reading this awesome article I decided to write my own version of exactly what I saw in his pictures:

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
end

puts "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


I had a kind of program which would find primes higher than the Sieve of Eratosthenes (typically this only goes up to 4 billion because of 1 bit per integer), called a 'Leapfrog' sieve, but someone said it wasn't very interesting, and I can't tell if it's been done before.


Prime Links - http://primes.utm.edu/links/programs/ - doesn't have anything about Leapfrog.

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).


it's called a 'sliding window sieve'.


Someone should tell this guy about google docs..


And the GIF file format




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: