Skip to content

Instantly share code, notes, and snippets.

@AnthonyMikh
Created January 27, 2018 21:20
Show Gist options
  • Save AnthonyMikh/493da23902f380c89aeaadac41b73903 to your computer and use it in GitHub Desktop.
Save AnthonyMikh/493da23902f380c89aeaadac41b73903 to your computer and use it in GitHub Desktop.
Решение задачи №65 от Unilecs (вариант с массивами)
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
@AnthonyMikh
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment