Guest User

Untitled

a guest
Dec 12th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. import scala.math._
  2.  
  3. def isRightTriangle(longestSide: Int, sideA: Int, sideB: Int): Boolean =
  4. pow(longestSide, 2).toInt == (pow(sideA, 2) + pow(sideB, 2)).toInt
  5.  
  6. def countRightTriangles(girth: Int): Int = {
  7. ((girth / 3).toInt to (girth / 2).toInt).map { l =>
  8. 1 to (girth - l) / 2 count(s => isRightTriangle(l, s, girth - l - s))
  9. }.sum
  10. }
  11.  
  12. println(3 to 1000 maxBy(countRightTriangles))
  13. // => 840
Add Comment
Please, Sign In to add comment