Skip to content

Instantly share code, notes, and snippets.

@jonathanpike
Created October 20, 2015 15:41
Show Gist options
  • Save jonathanpike/befb9714cb431700443a to your computer and use it in GitHub Desktop.
Save jonathanpike/befb9714cb431700443a to your computer and use it in GitHub Desktop.
# With help from: http://math.stackexchange.com/questions/389675/largest-prime-factor-of-600851475143
def largest_prime_factor(number)
divisor = 2
largest_divisor = 0
until number == 1
if number % divisor == 0
number /= divisor
largest_divisor = divisor
else
divisor += 1
end
end
largest_divisor
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment