• + 0 comments

    Monads are fun

    module Main (main) where
    
    import           Control.Monad
    
    main :: IO ()
    main = do
      pointCount <- read <$> getLine
      points     <- replicateM pointCount (fmap read . head . reads <$> getLine)
      print $   sum
            $   zipWith (\(x1, y1) (x2, y2) -> sqrt $ (x2 - x1) ** 2 + (y2 - y1) ** 2)
            <*> tail
            $   take (pointCount + 1)
            $   cycle points