Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.math._
- def isRightTriangle(longestSide: Int, sideA: Int, sideB: Int): Boolean =
- pow(longestSide, 2).toInt == (pow(sideA, 2) + pow(sideB, 2)).toInt
- def countRightTriangles(girth: Int): Int = {
- ((girth / 3).toInt to (girth / 2).toInt).map { l =>
- 1 to (girth - l) / 2 count(s => isRightTriangle(l, s, girth - l - s))
- }.sum
- }
- println(3 to 1000 maxBy(countRightTriangles))
- // => 840
Add Comment
Please, Sign In to add comment