Skip to content

Instantly share code, notes, and snippets.

@arn-e
Created October 8, 2012 03:57
Show Gist options
  • Save arn-e/3850646 to your computer and use it in GitHub Desktop.
Save arn-e/3850646 to your computer and use it in GitHub Desktop.
recursive_prime_factorization
def prime_factors(n, factors = [], f = 2)
return factors.push(f) if n == f
n % f == 0 ? prime_factors(n / f, factors.push(f)) : prime_factors(n, factors, f + 1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment