summaryrefslogtreecommitdiff
path: root/11-20/11.hs
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2017-05-28 19:08:02 -0400
committerDeterminant <ted.sybil@gmail.com>2017-05-28 19:08:02 -0400
commitb2d6f0e28dac922ac4ed5c55f79d0dd38f4765d2 (patch)
tree8b89e89ee7ae2dcc6723536bdc76e795a2abd108 /11-20/11.hs
parentafae39a832fbdf0f5bf67e20cac7bdf224b0a290 (diff)
...
Diffstat (limited to '11-20/11.hs')
-rw-r--r--11-20/11.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/11-20/11.hs b/11-20/11.hs
new file mode 100644
index 0000000..a64fdc2
--- /dev/null
+++ b/11-20/11.hs
@@ -0,0 +1,14 @@
+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
+
+data ListItem a = Single a | Multiple Int a deriving Show
+encodeModified :: Eq a => [a] -> [ListItem a]
+
+encodeModified xs = map (\x -> let l = length x
+ h = head x in
+ case l of
+ 1 -> Single h
+ otherwise -> Multiple l h) $ pack xs