Skip to content

Instantly share code, notes, and snippets.

@hankliu5
Last active December 5, 2015 03:02
Show Gist options
  • Save hankliu5/c7ee4a42510de883b4e9 to your computer and use it in GitHub Desktop.
Save hankliu5/c7ee4a42510de883b4e9 to your computer and use it in GitHub Desktop.
Which can help us pick up prime numbers in the range of a number you choose.
puts "Enter an number greater than 1."
number = gets.chomp.to_i
puts "I'm gonna pick up prime numbers less than #{number}."
range = Array.new
initial_value = 2
(number - 1).times { range << initial_value; initial_value += 1 }
range.each do |i|
i_square = i ** 2
while i_square <= number
range.delete(i_square)
i_square += i
end
end
puts range
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment