Skip to content

Instantly share code, notes, and snippets.

@jdee
Created September 7, 2010 18:28
Show Gist options
  • Save jdee/568796 to your computer and use it in GitHub Desktop.
Save jdee/568796 to your computer and use it in GitHub Desktop.
#!/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