From 8fc6e8acbc980038ec9186a2c05dc2349ea8dd49 Mon Sep 17 00:00:00 2001 From: Rnhmjoj Date: Sun, 8 Mar 2015 01:34:19 +0100 Subject: [PATCH] Add group function --- Matrix.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Matrix.hs b/Matrix.hs index febbd0b..dc66cd4 100644 --- a/Matrix.hs +++ b/Matrix.hs @@ -19,6 +19,11 @@ xs ?? n | n < 0 = Nothing (x:_) ?? 0 = Just x (_: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 indeces :: Mat a -> Mat Pos indeces (Mat m) = Mat [[(x,y) | y <- [0..length (m !! x)-1]] |