Project Euler

Problem #9

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,

a^(2) + b^(2) = c^(2)

For example, 3^(2) + 4^(2) = 9 + 16 = 25 = 5^(2).

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.

Erlang: Running time = 0.473s
p9()->p9(334).
p9(C)->p9(1,C).
p9(C,C)->p9(1,C+1);
p9(B,C)->
	A=1000-C-B,
	if
		C*C == A*A + B*B->
			io:format("~w~n",[A*B*C]);
		true->
			p9(B+1,C)
	end.

Ruby: Running time = 0.338s
def p9
  (2..500).each do |a|
    (1...a).each do |b|
      if(a**2+b**2==(1000-a-b)**2)
        puts a*b*(1000-a-b)
        return
      end
    end
  end
end

Scala: Running time = 0.5s
+//pow

def p9{
  for(c<-334 to 1000; b<-2 to (c-1)){
    if(c*c==b*b+pow(1000-c-b,2).intValue)
    {
      println(c*b*(1000-c-b))
      return
    }
  }
}