Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.61 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def abundant(num)
  2.   result = 0
  3.   Integer(num/2+1).downto(1) do |factor|
  4.     if num % factor == 0
  5.       # factors.append(factor)
  6.       result += factor
  7.     end
  8.   end
  9.   return result > num
  10. end
  11.  
  12. puts 'Finding all the abundant numbers...'
  13.  
  14. isAbundant = []
  15. result = 0
  16.  
  17. (1..28123).each do |number|
  18.   if abundant(number)
  19.     isAbundant << number
  20.   end
  21. end
  22.  
  23. puts 'found all the abundant numbers...'
  24.  
  25. possibilities = (1..28123).to_a
  26.  
  27. isAbundant.each do |factorOne|
  28.   isAbundant.each do |factorTwo|
  29.     possibilities.delete(factorOne + factorTwo)
  30.   end
  31. end
  32.  
  33. # print sum of the remaining possibilities
  34. puts possibilities.inject{:+}