Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created April 29, 2010 22:57
Show Gist options
  • Save workmad3/384408 to your computer and use it in GitHub Desktop.
Save workmad3/384408 to your computer and use it in GitHub Desktop.
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