Run-length encoding: Difference between revisions
Content added Content deleted
(→Haskell :: As a fold: Slight reduction – pruned out an import.) |
|||
Line 2,930: | Line 2,930: | ||
encoded = runLengths testString |
encoded = runLengths testString |
||
putStrLn $ showLengths encoded |
putStrLn $ showLengths encoded |
||
print $ |
|||
concatMap (uncurry replicate) encoded == testString |
|||
------------------------- DISPLAY ------------------------ |
------------------------- DISPLAY ------------------------ |
||
showLengths :: [(Int, Char)] -> String |
showLengths :: [(Int, Char)] -> String |
||
showLengths [] = [] |
showLengths [] = [] |
||
showLengths ((n, c) : xs) = show n <> [c] <> showLengths xs</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre>12W1B12W3B24W1B14W |
<pre>12W1B12W3B24W1B14W |