diff options
Diffstat (limited to 'p10.hs')
-rw-r--r-- | p10.hs | 20 |
1 files changed, 0 insertions, 20 deletions
@@ -1,20 +0,0 @@ -import Control.Applicative -import Control.Arrow -import Data.List - -encode :: Eq a => [a] -> [(a,Int)] -encode = foldr elim [] - where - elim e [] = [(e,1)] - elim e p@(n:ns) - | e == fst n = (e,1 + (snd n)):ns - | otherwise = (e,1):p - -encode' (x:xs) = let (first,rest) = span (==x) xs - in (x,1+(length first)) : encode' rest - -encode' [] = [] - -encode'' xs = map (head &&& length) $ group xs - -encode''' xs = map ((,) <$> head <*> length) $ group xs |