Skip to content

Instantly share code, notes, and snippets.

View mchav's full-sized avatar

Michael Chavinda mchav

View GitHub Profile
54044
14108
79294
29649
25260
60660
2995
53777
49689
9083
@mchav
mchav / inversions.hs
Created June 17, 2016 15:31
Counting inversions Haskell.
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
@mchav
mchav / inversions.py
Created June 17, 2016 15:30
Coutning inversions - python
## 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]