Created
December 19, 2011 14:54
-
-
Save kkirsanov/1497547 to your computer and use it in GitHub Desktop.
RLE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (group) | |
rle:: String -> [(Char, Int)] | |
rle [] = error "Empty List" | |
rle [x] = [(x, 1)] | |
rle st@(x:xs) = (head start, cnt) : rle ending where | |
start = takeWhile (==x) st | |
cnt = length start | |
ending = drop cnt st | |
-- with library | |
rle2:: String -> [(Char, Int)] | |
rle2 = map (\g -> (head g, length g)) . group |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment