Created
December 28, 2009 16:34
-
-
Save Riduidel/264765 to your computer and use it in GitHub Desktop.
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 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