We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
objectPerimeterextendsApp{caseclassPoint(valx:Int,valy:Int){defdistance(p:Point):Double=Math.sqrt(Math.pow(x-p.x,2)+Math.pow(y-p.y,2))}valpoints//asume points is a points list, and you have read it and map it from input already@tailrecdefrecAux(ls:List[Point],first:Point,acc:Double):Double=lsmatch{caseNil=>0casex::Nil=>acc+x.distance(first)//compare distance between first and lastcasex::x1::xs=>recAux(x1::xs,first,acc+x.distance(x1))}valtot=recAux(points,points.head,0)println(tot)}
Compute the Perimeter of a Polygon
You are viewing a single comment's thread. Return to all comments →
scala tail recursive approach: