Skip to content

Instantly share code, notes, and snippets.

@Riduidel
Created December 28, 2009 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Riduidel/264765 to your computer and use it in GitHub Desktop.
Save Riduidel/264765 to your computer and use it in GitHub Desktop.
def MAX = 1000;
def get(max) {
def results = [:]
for(i in 1..max) {
for(j in i..max) {
def sum = i*i+j*j;
double sqrt = Math.sqrt(sum);
if(sqrt==sqrt.round()) {
results[[i,j]]=sqrt.round();
}
}
}
return results;
}
long start = System.currentTimeMillis();
results = get(MAX);
results.each {key, value ->
if(key[0]+key[1]+value==MAX) {
println key.join(", ")+", "+value+" = "+(key[0]*key[1]*value);
}
}
long end = System.currentTimeMillis();
println "duration "+((end-start)/1000.0)+" s";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment