Skip to content

Instantly share code, notes, and snippets.

@slagyr
Created May 11, 2011 19:36
Show Gist options
  • Save slagyr/967151 to your computer and use it in GitHub Desktop.
Save slagyr/967151 to your computer and use it in GitHub Desktop.
Prime Factors in Ruby
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