• + 0 comments

    my haskell solution:

    import Control.Monad 
    
    euclidean[x1,y1] [x2,y2] = sqrt $ (x2 - x1)**2 + (y2 - y1)**2
    
    solve n points = sum $ zipWith euclidean pairs (tail pairs ++ [head pairs])
      where
        pairs = map ((\[a, b] -> [read a, read b]) . words) points :: [[Double]]
    
    main = do
        n <- readLn :: IO Int 
        input <- replicateM n getLine
        print $ solve n input