Skip to content

Instantly share code, notes, and snippets.

@ccw
Created March 26, 2012 04:27
Show Gist options
  • Save ccw/2202923 to your computer and use it in GitHub Desktop.
Save ccw/2202923 to your computer and use it in GitHub Desktop.
[Project Euler in Groovy] - P3
def primes = [2, 3, 5, 7, 11, 13, 17]
def MAX = 600851475143
def factor = 0
def i = primes.get(primes.size() - 1) + 1
while (MAX > 1) {
if(!primes.any { i % it == 0 }) {
primes << i
if (MAX % i == 0) {
factor = i
MAX = (long)(MAX/i)
println "current factor => $factor"
}
}
i++
}
println factor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment