You are viewing a single comment's thread. Return to all comments →
Here is my Haskell solution:
myPair :: [a] -> [(a, a)] myPair [] = [] myPair [a] = [] myPair (a0:a1:as) = (a0, a1) : myPair as distance :: (Float, Float) -> (Float, Float) -> Float distance a b = sqrt $ (fst b - fst a) ** 2 + (snd b - snd a) ** 2 totalDistance :: [(Float, Float)] -> Float totalDistance [] = 0 totalDistance [a] = 0 totalDistance (a0:a1:as) = distance a0 a1 + totalDistance (a1:as) parameter :: [Float] -> Float parameter a = let pairs = myPair a in totalDistance pairs + distance (last pairs) (head pairs) main :: IO () main = do _ <- getLine x <- getContents let f = map (read::String->Float) $ words x print (parameter f)
Compute the Perimeter of a Polygon
You are viewing a single comment's thread. Return to all comments →
Here is my Haskell solution: