Scala: Project Euler: Problem 9
November 26th, 2009
Problem:
Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000.
object Problem9 {
def main(args: Array[String]) :Unit = {
val list = findPythagoreanTriplets(1000)
val product = list.first._1 * list.first._2 * list.first._3
println(product)
}
def findPythagoreanTriplets(number:Int) : List[Tuple3[Int, Int, Int]] = {
for{ a <- 1.to(number - 1)
b <- (a+1).to(number)
c = number - a - b
if(a*a + b*b == c*c)
} return List((a,b,c))
return List()
}
}