Created
August 12, 2010 09:54
-
-
Save radar/520658 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
class Numeric | |
def prime? | |
basics = (2..10).to_a | |
return false if basics.detect { |n| self % n == 0 } | |
factors == [1, self] | |
end | |
def factors | |
@factors ||= (1..self).to_a.select { |n| self % n == 0 } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice solution! Just out of curiosity, was my attempt just way off or was the approach doable but with some minor error/bug?