Run-length encoding: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: Version 2) |
(→Version 2: improvement) |
||
Line 1,686: | Line 1,686: | ||
runLengthEncode = concatMap (\xs@(x:_) -> (show.length $ xs) ++ [x]).group |
runLengthEncode = concatMap (\xs@(x:_) -> (show.length $ xs) ++ [x]).group |
||
runLengthDecode = concat.uncurry (zipWith (\[x] ns -> replicate (read ns) x)) |
|||
.foldr (\z (x,y) -> (y,z:x)) ([],[]).groupBy (\x y -> all isDigit [x,y]) |
|||
where |
|||
go (n,ls) [x] | not.isDigit $ x = (0,replicate n x : ls) |
|||
go (n,ls) ns = (read ns,ls) |
|||
main = do |
main = do |