Skip to content

Instantly share code, notes, and snippets.

@erdostom
Created December 7, 2019 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erdostom/8b48b9c24d3211502f4a9a946e10ccb4 to your computer and use it in GitHub Desktop.
Save erdostom/8b48b9c24d3211502f4a9a946e10ccb4 to your computer and use it in GitHub Desktop.
print prime factors
def get_factors(number)
(2...number).each do |n|
if number % n == 0
return [get_factors(n), get_factors(number / n)]
end
end
return number
end
def print_factors(number)
p [get_factors(number)].flatten.uniq
end
print_factors 600851475143
# [71, 839, 1471, 6857]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment