Created
January 2, 2017 01:42
-
-
Save keevie/6b84a0fd8b3a50ff6b3bfea0ad9e83b3 to your computer and use it in GitHub Desktop.
This file contains 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_factorization(num) | |
return [] if num == 1 | |
2.upto(num - 1).each do |factor| | |
if num % factor == 0 | |
return [factor] + prime_factorization(num / factor) | |
end | |
end | |
[num] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment