Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@qtamaki
Created December 3, 2012 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qtamaki/4193879 to your computer and use it in GitHub Desktop.
Save qtamaki/4193879 to your computer and use it in GitHub Desktop.
RLE
tails :: String -> [String]
tails [] = []
tails (x:[]) = [[x]]
tails (x:xs) = (x:xs) : tails xs
isDigit :: Char -> Bool
isDigit x = '0' < x && x < '9'
f :: String -> String -> String
f (xs) (y:[]) = xs
f (x:xs) (y1:y2:ys) = if y1 == y2
then if isDigit x
then (show (1 + (read (x:""))::Int)) ++ xs
else '2' : x : xs
else
y2 : x : xs
rle :: String -> String
rle (x:xs) = reverse $ foldl f [x] $ tails (x:xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment