Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/usr/bin/env ruby
#
def help
puts "#{$0} <find_primes_to>"
end
def find_primes(array_list)
array_list.each do |num|
i = num
if num * i > array_list.last
break
else
while num * i <= array_list.last
array_list.delete(num * i)
i += 1
end
end
end
return array_list
end
begin
unless ARGV.length == 1
help
exit(1)
end
prime_to = ARGV[0]
array_list = []
prime_to = prime_to.to_i + 1
prime_to.times {|d| array_list << d}
[0,1].each {|n| array_list.delete(n) }
results = find_primes(array_list)
print "#{results}\n"
rescue => e
puts "#{e}"
exit(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.