Created
March 26, 2012 04:27
-
-
Save ccw/2202923 to your computer and use it in GitHub Desktop.
[Project Euler in Groovy] - P3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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