Last active
October 12, 2017 10:50
-
-
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). :(
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
#!/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