[Solved] How can I find the prime numbers between 1 to the given number, only by using the loop(ie. without any short cuts) in “Ruby”? [duplicate]


This does feel a lot like a school project/task rather than anything meaningful. There are libraries built into Ruby that you can use for high performance Prime calculations

puts "Enter the maximum number of the range in which to find the prime numbers: "
last = gets.chomp.to_i
prime = [2]
all_numbers = (2..last).to_a

print "We are going to separate the prime numbers and non prime numbers from the elements present in this array: #{all_numbers}\n\n"

all_numbers.each do |i|
  prime.push i unless prime.any? { |x| i % x == 0 }
end

print "The prime numbers are: #{prime}\n\n" 
print "The non-prime numbers are: #{all_numbers - prime}\n"

solved How can I find the prime numbers between 1 to the given number, only by using the loop(ie. without any short cuts) in “Ruby”? [duplicate]