Skip to content

Instantly share code, notes, and snippets.

@styd
Last active October 12, 2017 10:50
Show Gist options
  • Save styd/655bd150a79696b85897674dc78e9e45 to your computer and use it in GitHub Desktop.
Save styd/655bd150a79696b85897674dc78e9e45 to your computer and use it in GitHub Desktop.
A stupid job post on Upwork asking to write this. An easy US$ 8 I missed (didn't get the job). :(
#!/usr/bin/env ruby
print "Enter a number: "
input = gets.to_i
divisors = []
(2...input).each do |i|
divisors << i if input % i == 0
end
if divisors.empty?
puts "#{input} is a prime number"
else
puts "#{input} is not a prime number => #{divisors.join(', ')}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment