Created
January 27, 2018 21:20
-
-
Save AnthonyMikh/493da23902f380c89aeaadac41b73903 to your computer and use it in GitHub Desktop.
Решение задачи №65 от Unilecs (вариант с массивами)
This file contains hidden or 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
import qualified Data.Vector.Unboxed as V | |
import Control.Arrow ((***), (&&&)) | |
(&) = flip ($) | |
infixl 0 & | |
shiftedZipWith f vec = | |
enumFromTo 0 (len-1) | |
& map index &&& map (index . (`rem` len) . (+1)) | |
& uncurry (zipWith f) | |
where | |
len = V.length vec | |
index = (vec V.!) | |
shiftedSum = shiftedZipWith (+) | |
shiftedFSub = shiftedZipWith (flip (-)) | |
polygonArea = curry $ (/2) . fromIntegral . abs . sum . uncurry (zipWith (*)) . (***) shiftedSum shiftedFSub | |
main = | |
let a = V.fromList [0 :: Int, 0, 2] | |
b = V.fromList [0 :: Int, 2, 0] | |
in print $ polygonArea a b -- 2.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Playground: https://paiza.io/projects/P8EvgVn0Wo3ft6nSZ5zpgg?language=haskell