Skip to content

Commit

Permalink
Add haskell solution to Compute the Area of a Polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusfk9 committed Nov 1, 2019
1 parent bda8298 commit 927fd26
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 927fd26

Please sign in to comment.