Skip to content

Instantly share code, notes, and snippets.

@jaredcacurak
Created February 24, 2011 02:31
Show Gist options
  • Save jaredcacurak/841645 to your computer and use it in GitHub Desktop.
Save jaredcacurak/841645 to your computer and use it in GitHub Desktop.
A Groovy solution for Project Euler - Problem 3
def largestPrimeFactorOf = { BigInteger it, divisor = 1, factors = [] ->
while (it > 1) {
divisor += 1
while (it % divisor == 0) {
factors << divisor
it /= divisor
}
}
factors.last()
}
assert largestPrimeFactorOf(600851475143) == 6857
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment