Created
April 29, 2010 22:57
-
-
Save workmad3/384408 to your computer and use it in GitHub Desktop.
This file contains 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
class Fixnum | |
def amicable? | |
b = self.divisors.sum | |
return b != self && b.divisors.sum == self | |
end | |
def divisors | |
(1..self/2).select{|x| self % x == 0} | |
end | |
end | |
class Array | |
def sum | |
self.inject(0, &:+) | |
end | |
end | |
(1..10000).select(&:amicable?).sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment