=begin rdoc == Sieve of Eratosthenes Use the Sieve of Eratosthenes algorithm to generate a list of prime numbers. The method is an introduction to iteration, using iterators to make and filter lists of numbers, and a while loop to repeat the filtering step until no more composite numbers are left in the worksheet. =end module RubyLabs module SieveLab =begin rdoc Call +sieve(n)+ to create an array of prime numbers between +2+ and +n+ =end # :begin :sieve def sieve(n) worksheet = Array(2..n) primes = [] while worksheet.first < sqrt(n) primes << worksheet.first worksheet.delete_if { |x| x % primes.last == 0 } end return primes + worksheet end # :end :sieve end # SieveLab end # RubyLabs