diff options
author | Determinant <ted.sybil@gmail.com> | 2017-05-28 19:08:02 -0400 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2017-05-28 19:08:02 -0400 |
commit | b2d6f0e28dac922ac4ed5c55f79d0dd38f4765d2 (patch) | |
tree | 8b89e89ee7ae2dcc6723536bdc76e795a2abd108 /11-20/13.hs | |
parent | afae39a832fbdf0f5bf67e20cac7bdf224b0a290 (diff) |
...
Diffstat (limited to '11-20/13.hs')
-rw-r--r-- | 11-20/13.hs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/11-20/13.hs b/11-20/13.hs new file mode 100644 index 0000000..db5509e --- /dev/null +++ b/11-20/13.hs @@ -0,0 +1,10 @@ +data ListItem a = Single a | Multiple Int a deriving Show +encodeDirect :: Eq a => [a] -> [ListItem a] + +encodeDirect [] = [] +encodeDirect [x] = [Single x] +encodeDirect (x:xs) = if x == h then n:ys else (Single x):(y:ys) + where (y:ys) = encodeDirect xs + helper (Single z) = (Multiple 2 z, z) + helper (Multiple c z) = (Multiple (c + 1) z, z) + (n, h) = helper y |