Skip to content

Instantly share code, notes, and snippets.

@nategraves
Created June 24, 2015 19:00
Show Gist options
  • Save nategraves/d52f45a687de48427fa4 to your computer and use it in GitHub Desktop.
Save nategraves/d52f45a687de48427fa4 to your computer and use it in GitHub Desktop.
print "Enter a number: "
user_number = gets.to_i
# Lets say I put in 57
count = 2
check = []
# Is count (2) less than or equal to 58? it is, so I'll run the loop
while count <= user_number+1
#if the remainder of 57 / 2 is 0
if user_number % count == 0
# then add 2 to my array unless 2 equals 57 which it doesn't
check.push(count) unless count == user_number
end
#count should now be 3
count+=1
end
if check.empty?
puts "#{user_number} is a prime number."
else
puts "#{user_number} is divisible by #{check}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment