You are viewing a single comment's thread. Return to all comments →
Any idea why I'm getting RunTime exception when posting solution below? Works fine on my machine
RunTime exception
object Solution { def dist(p1:(Int, Int), p2:(Int, Int)): Double = { math.sqrt(math.pow((p1._1 - p2._1),2) + math.pow((p1._2 - p2._2),2)) } def main(args: Array[String]) { val pointsNum = scala.io.StdIn.readInt() val points = io.Source.stdin.getLines().take(pointsNum).map(line => line.split(" ")).map(arr => (arr(0).toInt, arr(1).toInt)).toArray println(points.foldLeft((0.0, points.last)) { (acc, point) => (acc._1 + dist(acc._2, point), point) }._1) } }
Compute the Perimeter of a Polygon
You are viewing a single comment's thread. Return to all comments →
Any idea why I'm getting
RunTime exception
when posting solution below? Works fine on my machine