
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 0.61 KB | hits: 16 | expires: Never
def abundant(num)
result = 0
Integer(num/2+1).downto(1) do |factor|
if num % factor == 0
# factors.append(factor)
result += factor
end
end
return result > num
end
puts 'Finding all the abundant numbers...'
isAbundant = []
result = 0
(1..28123).each do |number|
if abundant(number)
isAbundant << number
end
end
puts 'found all the abundant numbers...'
possibilities = (1..28123).to_a
isAbundant.each do |factorOne|
isAbundant.each do |factorTwo|
possibilities.delete(factorOne + factorTwo)
end
end
# print sum of the remaining possibilities
puts possibilities.inject{:+}