Created
September 7, 2010 18:28
-
-
Save jdee/568796 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
#!/usr/bin/env ruby | |
class Fixnum | |
def is_perfect | |
(1...self).select { |x| self % x == 0 }.inject(:+) == self | |
end | |
end | |
def first_perfect | |
j = 2 | |
loop do | |
return j if j.is_perfect | |
j += 1 | |
end | |
end | |
puts first_perfect - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment