Created
July 23, 2016 08:49
-
-
Save rhaseven7h/78928ea594aefbdf6c744ce0a57f17bd to your computer and use it in GitHub Desktop.
HackerRank.com - Functional Programming - Haskell - Compute The Area Of A Polygon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 | |
458 695 | |
621 483 | |
877 469 | |
1035 636 | |
1061 825 | |
875 1023 | |
645 1033 | |
485 853 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
255931.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment