Skip to content

Instantly share code, notes, and snippets.

@calmvp
Created July 20, 2013 20:49
Show Gist options
  • Save calmvp/6046399 to your computer and use it in GitHub Desktop.
Save calmvp/6046399 to your computer and use it in GitHub Desktop.
def prime_factors(number)
factors = []
2.upto(number/2) do |possible_divisor|
if number % possible_divisor == 0
factors << possible_divisor
prime_factors(number /= possible_divisor)
end
end
if number > 1
factors << number
end
factors
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment