Skip to content

Instantly share code, notes, and snippets.

@ysnerdem
Created March 15, 2018 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysnerdem/95e46b80c77be2ecc796ce0e5f92d806 to your computer and use it in GitHub Desktop.
Save ysnerdem/95e46b80c77be2ecc796ce0e5f92d806 to your computer and use it in GitHub Desktop.
Deficient Numbers #3 different method
def is_deficient(num)
sum = 0
(1..num).each {|i| sum += i if num % i == 0}
if sum < (2 * num)
"#{num} is deficient number"
else
"#{num} is not deficient number"
end
end
def find_deficients(range)
(1..range).each do |num|
sum = 0
(1..num).each {|i| sum += i if num % i == 0}
if sum < (2 * num)
puts num
end
end
end
def is_deficient_v2(num)
sum = 0
print "Factors: "
(1..num).each do |i|
if num % i == 0
print "#{i}, "
sum += i
end
end
print "\nSum of factors: #{sum}"
if sum < (num * 2)
print "\n#{num} is deficient number"
else
print "\n#{num} is not deficient number"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment