Skip to content

Instantly share code, notes, and snippets.

@KevinSia
Created September 12, 2017 17:25
Show Gist options
  • Save KevinSia/82fba690b4b05e6c380853de1956c6d0 to your computer and use it in GitHub Desktop.
Save KevinSia/82fba690b4b05e6c380853de1956c6d0 to your computer and use it in GitHub Desktop.
def prime_factors(num)
return [num] if num <= 1
result = []
until num == 1
for i in (2..num)
if num % i == 0
result << i
num /= i
break
end
end
end
return result
end
def prime_factors(num)
return [num] if num <= 1
result = []
i = 2
until num == 1
if num % i == 0
result << i
num /= i
i = 2
else
i += 1
end
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment