summaryrefslogtreecommitdiff
path: root/1-10/10.hs
diff options
context:
space:
mode:
Diffstat (limited to '1-10/10.hs')
-rw-r--r--1-10/10.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/1-10/10.hs b/1-10/10.hs
new file mode 100644
index 0000000..0cc6a9a
--- /dev/null
+++ b/1-10/10.hs
@@ -0,0 +1,9 @@
+pack :: Eq a => [a] -> [[a]]
+
+pack [] = []
+pack [x] = [[x]]
+pack (x:xs) = if x == head y then (x:y):ys else [x]:(y:ys) where (y:ys) = pack xs
+
+encode :: Eq a => [a] -> [(Int, a)]
+
+encode xs = map (\x -> (length x, head x)) $ pack xs