You are viewing a single comment's thread. Return to all comments →
import Control.Monad type Point = (Float, Float) type Line = (Point, Point) toTuple (x:y:[]) = (x,y) distance :: Line -> Float distance ((x1,y1),(x2,y2)) = sqrt((x2-x1)^2 + (y2-y1)^2) main :: IO () main = do n <- readLn :: IO Int points <- replicateM n (toTuple <$> (map read) <$> words <$> getLine) :: IO [Point] let lines = zip points (tail $ cycle points) let result = sum $ map distance lines print result
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 →