summaryrefslogtreecommitdiff
path: root/p9.hs
diff options
context:
space:
mode:
Diffstat (limited to 'p9.hs')
-rw-r--r--p9.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/p9.hs b/p9.hs
new file mode 100644
index 0000000..b190491
--- /dev/null
+++ b/p9.hs
@@ -0,0 +1,13 @@
+pack :: (Eq a) => [a] -> [[a]]
+pack = foldr elim []
+ where elim e [] = [[e]]
+ elim e p@(n:ns)
+ | e == head n = (e:n):ns
+ | otherwise = [e]:p
+
+pack' (x:xs) = let (first,rest) = span (==x) xs
+ in (x:first) : pack' rest
+pack' [] = []
+
+pack'' (x:xs) = (x:takeWhile (==x) xs):(pack'' $ dropWhile (==x) xs)
+pack'' [] = []