You are viewing a single comment's thread. Return to all comments →
Scala
Lazy all the way
object Solution extends App { val n = readLine.toInt val v0 = readLine val vs = (Iterator(v0) ++ Iterator.continually(readLine) .take(n-1) ++ Iterator(v0)) .map(_.split(" ").map(_.toInt)) val es = vs.sliding(2) val ds = es.map{ case Seq(Array(x1,y1),Array(x2,y2)) => math.hypot(x1-x2,y1-y2) } println(ds.sum) }
Seems like cookies are disabled on this browser, please enable them to open this website
Compute the Perimeter of a Polygon
You are viewing a single comment's thread. Return to all comments →
Scala
Lazy all the way