Last active
December 30, 2015 09:09
-
-
Save jonelf/7807551 to your computer and use it in GitHub Desktop.
Tests if a number is weird.
This file contains hidden or 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
70.weird?
=> true