23 lines
442 B
Haskell
23 lines
442 B
Haskell
msort :: Ord a => [a] -> [a]
|
|
msort [] = []
|
|
msort [x] = [x]
|
|
msort x = merge (msort a) (msort b)
|
|
where (a,b) = splitAt (length x `div` 2) x
|
|
|
|
|
|
merge :: Ord a => [a] -> [a] -> [a]
|
|
merge x [] = x
|
|
merge [] y = y
|
|
merge (x:xs) (y:ys)
|
|
| x <= y = x : merge xs (y:ys)
|
|
| otherwise = y : merge ys (x:xs)
|
|
|
|
|
|
gcd' :: Int -> Int -> Int
|
|
gcd' 1 m = 1
|
|
gcd' n 1 = 1
|
|
gcd' n m
|
|
| n == m = n
|
|
| n > m = gcd' m (n-m)
|
|
| otherwise = gcd' n (m-n)
|