Last active
December 5, 2015 03:02
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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