Skip to content

Instantly share code, notes, and snippets.

@keevie
Created January 2, 2017 01:42
Show Gist options
  • Save keevie/6b84a0fd8b3a50ff6b3bfea0ad9e83b3 to your computer and use it in GitHub Desktop.
Save keevie/6b84a0fd8b3a50ff6b3bfea0ad9e83b3 to your computer and use it in GitHub Desktop.
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