Add group function

This commit is contained in:
Rnhmjoj 2015-03-08 01:34:19 +01:00
parent 18fe09a531
commit 8fc6e8acbc

View File

@ -19,6 +19,11 @@ xs ?? n | n < 0 = Nothing
(x:_) ?? 0 = Just x (x:_) ?? 0 = Just x
(_:xs) ?? n = xs ?? (n-1) (_:xs) ?? n = xs ?? (n-1)
-- | Split a list into sublists of length n
-- group 2 [1..5] == [[1,2],[3,4],[5]]
group _ [] = []
group n xs = take n xs : group n (drop n xs)
-- | Create a matrix of indeces of a matrix -- | Create a matrix of indeces of a matrix
indeces :: Mat a -> Mat Pos indeces :: Mat a -> Mat Pos
indeces (Mat m) = Mat [[(x,y) | y <- [0..length (m !! x)-1]] | indeces (Mat m) = Mat [[(x,y) | y <- [0..length (m !! x)-1]] |