public override string GetAnswer() { const int tripletSum = 1000; List <Triangle> triangles = TriangleUtilities.GetRightTrianglesWithPerimeter(tripletSum); if (triangles.Count > 0) { return(triangles[0].SideProduct.ToString()); } return(null); }
public override string GetAnswer() { // Iterate through values of p. // Find all values of a, b, c where a + b + c = p AND a^2 + b^2 = c^2 (AND a <= b < c) const int limit = 1000; int bestP = 0; int bestPCount = 0; // 3 + 4 + 5 = 12, start there. for (int p = limit; p >= 12; --p) { List <Triangle> triangles = TriangleUtilities.GetRightTrianglesWithPerimeter(p); if (triangles.Count > bestPCount) { bestP = p; bestPCount = triangles.Count; } } return(bestP.ToString()); }