You are viewing a single comment's thread. Return to all comments →
This is my solution:
import Control.Monad distancia :: [Int] -> [Int] -> Float distancia x y = sqrt $ fromIntegral ((((y!!0) - (x!!0 ))^2) + (((y!!1) - (x!!1))^2)) perimetro :: [[Int]] -> Float perimetro (x:xs) | length xs == 1 = (distancia x (xs!!0)) | otherwise = (distancia x (head xs)) + (perimetro xs) main :: IO () main = do line <- getLine let numPuntos :: Int numPuntos = read line poligono <- forM [1..numPuntos] (\a -> do linea <- getLine let vertice = map (read :: String -> Int) (words linea) return vertice ) putStrLn $ show (perimetro (poligono ++ [poligono!!0]))
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 →
This is my solution: