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
54044 | |
14108 | |
79294 | |
29649 | |
25260 | |
60660 | |
2995 | |
53777 | |
49689 | |
9083 |
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
import Control.Monad | |
inversions :: [Int] -> Int | |
inversions = snd . countInversions | |
countInversions :: [Int] -> ([Int], Int) | |
countInversions [] = ([] , 0) | |
countInversions [x] = ([x], 0) | |
countInversions arr = let mid = (length arr) `div` 2 | |
left = take mid arr |
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
## mergesort | |
def inversions(arr): | |
(array, inv) = count_inversions(arr) | |
return inv | |
def count_inversions(arr): | |
if len(arr) <= 1: | |
return (arr, 0) | |
mid = len(arr) / 2 | |
left = arr[:mid] |
NewerOlder