Skip to content

Instantly share code, notes, and snippets.

@ccw
Created March 26, 2012 04:34
Show Gist options
  • Save ccw/2202951 to your computer and use it in GitHub Desktop.
Save ccw/2202951 to your computer and use it in GitHub Desktop.
[Project Euler in Groovy] - P9
def t = 1000
def max_a = 332
def s = []
def max_b, min_c
for (int a = max_a; a > 0; a--) {
int c = min_c = (int)((t - a) / 2 + 1)
int b = max_b = t - a - min_c
while (c > b && b > a) {
def a2 = Math.pow(a, 2)
def b2 = Math.pow(b, 2)
def c2 = Math.pow(c, 2)
if(a2 + b2 == c2) {
s << (a * b * c)
break
}
c++
b--
}
if (s.size() > 0) break
}
println s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment