samskivert: Euler 039

01 June 2008

Problem 039:

object Euler39 extends Application {
  def sols (perim :Int) = perim + 1000 * (for {
    a <- List.range(1, perim/2);
    b <- List.range(1, (perim-a)/2+1);
    c <- List(perim-a-b);
    if (a*a + b*b == c*c)
  } yield 1).length;
  println(List.range(3, 1000).map(sols).foldLeft(0)(Math.max) % 1000);
}

Nothing fancy here, just a moderately brute force search.

©1999–2015 Michael Bayne