• + 3 comments
    object Solution {
    
      def main(args: Array[String]) {
    
        val N = scala.io.StdIn.readInt
        val points = scala.io.Source.stdin.getLines().take(N).map(x=>x).toList
        println(dist(points:+points.head ))
    
      }
      def dist(A: List[String]): Double = {
        if(A.length>=2)
          scala.math.sqrt(scala.math.pow((A(0).split(" ")(0).toDouble-A(1).split(" ")(0).toDouble),2) + scala.math.pow((A(0).split(" ")(1).toDouble-A(1).split(" ")(1).toDouble),2))+ dist(A.drop(1))
        else 0
      }
    }
    

    This is my scala code. It gives the correct output in my system but when I run it here, it gives me this error: java.util.NoSuchElementException: head of empty list