Skip to content

Instantly share code, notes, and snippets.

@jaredcacurak
Created February 24, 2011 02:06
Show Gist options
  • Save jaredcacurak/841612 to your computer and use it in GitHub Desktop.
Save jaredcacurak/841612 to your computer and use it in GitHub Desktop.
A Groovy solution for Project Euler - Problem 7
def candidate = 3
def listOfPrimes = [2]
while (listOfPrimes.size() < 10001) {
max = Math.sqrt(candidate)
for (prime in listOfPrimes) {
if (prime > max) {
listOfPrimes << candidate
break
}
if (candidate % prime == 0) {
break
}
}
candidate += 1
}
listOfPrimes.last()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment