summaryrefslogtreecommitdiff
path: root/21-28/27.hs
diff options
context:
space:
mode:
Diffstat (limited to '21-28/27.hs')
-rw-r--r--21-28/27.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/21-28/27.hs b/21-28/27.hs
new file mode 100644
index 0000000..434f66e
--- /dev/null
+++ b/21-28/27.hs
@@ -0,0 +1,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]