Guest User

Untitled

a guest
May 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.26 KB | None | 0 0
  1. class Fixnum
  2. def amicable?
  3. b = self.divisors.sum
  4. return b != self && b.divisors.sum == self
  5. end
  6.  
  7. def divisors
  8. (1..self/2).select{|x| self % x == 0}
  9. end
  10. end
  11. class Array
  12. def sum
  13. self.inject(0, &:+)
  14. end
  15. end
  16. (1..10000).select(&:amicable?).sum
Add Comment
Please, Sign In to add comment