summaryrefslogblamecommitdiff
path: root/1-10/10.hs
blob: 0cc6a9a8ae85c3f2c073037ea4808e60a9b1cbe1 (plain) (tree)
1
2
3
4
5
6
7
8
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