Created
May 11, 2011 19:36
-
-
Save slagyr/967151 to your computer and use it in GitHub Desktop.
Prime Factors in Ruby
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
module PrimeFactors | |
def self.of(n) | |
factors = [] | |
divisor = 2 | |
while n > 1 | |
while n % divisor == 0 | |
factors << divisor | |
n /= divisor | |
end | |
divisor += 1 | |
end | |
return factors | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment