Skip to content

Instantly share code, notes, and snippets.

@arn-e
Created October 8, 2012 05:24
Show Gist options
  • Save arn-e/3850857 to your computer and use it in GitHub Desktop.
Save arn-e/3850857 to your computer and use it in GitHub Desktop.
iterative prime factors
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