Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Perm = [Int]
- data Parity = Odd | Even deriving Show
- oddtest = [1,3,2,4,5] :: Perm
- eventest = [1,4,2,3,5] :: Perm
- genPairs :: Int -> [(Int, Int)]
- genPairs l = [(a,b) | a <- [1..l], b <- [1..l], a < b]
- inversion :: Perm -> (Int,Int) -> Bool
- inversion p (x,y) = o x > o y
- where
- o a = p !! (a-1)
- countInversions p = length $ filter id $ map (inversion p) $ genPairs $ length p
- parity :: Perm -> Parity
- parity p | even $ countInversions p = Even
- | otherwise = Odd
Add Comment
Please, Sign In to add comment