99haskell
99haskell copied to clipboard
exercise 10
In exercise 10 it's not clear that you need the previous function (from exercise 9) this is not really user friendly. Also imports do not work so you can not use the native pack or group functions from Data.List
pack (x:xs) = let (first,rest) = span (==x) xs
in (x:first) : pack rest
pack [] = []
encode :: Eq a => [a] -> [(Int, a)]
encode xs = (enc . pack) xs
where enc = foldr (\x acc -> (length x, head x) : acc) []