Skip to content

Instantly share code, notes, and snippets.

@jonelf
Last active December 30, 2015 09:09
Show Gist options
  • Save jonelf/7807551 to your computer and use it in GitHub Desktop.
Save jonelf/7807551 to your computer and use it in GitHub Desktop.
Tests if a number is weird.
class Fixnum
def weird?
divisors = (1..self/2+1).select{|n| self % n == 0 }
return false if self == 2 or divisors.reduce(:+) <= self
!(2..divisors.length-1).map{|m| divisors.combination(m).to_a }.flatten(1).any?{|a| a.reduce(:+) == self }
end
end
@jonelf
Copy link
Author

jonelf commented Dec 5, 2013

70.weird?
=> true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment