summaryrefslogblamecommitdiff
path: root/21-28/27.hs
blob: 434f66e96d839c8f48ff1500cccf1c524a58237d (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11










                                                                             
combinations :: Int -> [a] -> [([a], [a])]

combinations 0 xs = [([], xs)]
combinations _ [] = []
combinations k (x:xs) = [(x:t1, t2) | (t1, t2) <- combinations (k - 1) xs] ++
                        [(t1, x:t2) | (t1, t2) <- combinations k xs]

group :: [Int] -> [a] -> [[[a]]]

group _ [] = [[]]
group (n:ns) l = [a:r | (a, b) <- combinations n l, r <- group ns b]