Created
October 8, 2012 05:24
-
-
Save arn-e/3850857 to your computer and use it in GitHub Desktop.
iterative prime factors
This file contains hidden or 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
def prime_factors_iterative(n, f = 2, factors = []) | |
until n == f | |
n % f == 0 ? (factors, n, f = factors.push(f), (n/f), 2) : (f += 1) | |
end | |
return factors.push(f) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment