All pastes #747730 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-10-24 09:19 UTC
rendered paste body
import Data.List

encode :: (Eq a) => [a] -> [(Int, a)]
encode s = [(length run, head run) | run <- group s]

decode :: [Char] -> [Char]
decode s | s == [] = ""
         | otherwise = let (first, second) = span (\ch -> ch >= '0' && ch <= '9') s in
             replicate (read first :: Int) (head second) ++ decode (tail second)

-- vim: ts=4 sw=4 et