Skip to content

Instantly share code, notes, and snippets.

@rhaseven7h
Created July 23, 2016 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhaseven7h/78928ea594aefbdf6c744ce0a57f17bd to your computer and use it in GitHub Desktop.
Save rhaseven7h/78928ea594aefbdf6c744ce0a57f17bd to your computer and use it in GitHub Desktop.
HackerRank.com - Functional Programming - Haskell - Compute The Area Of A Polygon
main = do
raw <- getContents -- readFile "input.txt"
let toInts a = map (\e -> read e :: Int) a
noded = map toInts $ map words $ tail $ lines raw
nodec = length noded
xdata = map head noded
ydata = map last noded
sum1x = xdata
sum1y = (tail ydata) ++ [head ydata]
sum2x = (tail xdata) ++ [head xdata]
sum2y = ydata
sum1 = sum $ map (\(a, b) -> a * b) $ zip sum1x sum1y
sum2 = sum $ map (\(a, b) -> a * b) $ zip sum2x sum2y
sumN = abs $ sum1 - sum2
sumF = (fromIntegral sumN) / 2
putStrLn $ show sumF
8
458 695
621 483
877 469
1035 636
1061 825
875 1023
645 1033
485 853
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment