Skip to content

Commit

Permalink
Merge pull request #76 from viniciusfk9/perimeter_of_polygon
Browse files Browse the repository at this point in the history
Add Haskell solution to Compute the Perimeter of a Polygon
  • Loading branch information
anabastos authored Nov 24, 2019
2 parents d429692 + 927fd26 commit 137b733
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 1 - Introduction/25 - Compute the Area of a Polygon/viniciusfk9.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Control.Monad

f (p1, p2) (q1, q2) = fromIntegral (p1 * q2 - q1 * p2)

area lst = 0.5 * fromIntegral (abs . sum $ zipWith f lst (tail lst))

main = do
n <- fmap (read::String->Int) getLine
func <- forM [1..n] (\_->do
fmap ((\[a, b]->(a,b)) . map (read::String->Int).words) getLine :: IO (Int, Int))
putStrLn $ show (area (func ++ take 1 func))

0 comments on commit 137b733

Please sign in to comment.