Skip to content

Instantly share code, notes, and snippets.

@anthonylewis
Created July 24, 2008 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonylewis/2257 to your computer and use it in GitHub Desktop.
Save anthonylewis/2257 to your computer and use it in GitHub Desktop.
A Ruby Generator for prime numbers
require 'generator'
g = Generator.new do |g|
n = 2
p = []
while true
if p.all? { |f| n % f != 0 }
g.yield n
p << n
end
n += 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment