Created
June 8, 2016 21:04
-
-
Save comfly/70ed32850162b31b468eafce79eb7d77 to your computer and use it in GitHub Desktop.
Run length encoding
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
module Main where | |
import Data.Foldable | |
rle = (concatMap (\(sym, num) -> sym:show num)) . foldr' collect [] | |
where collect s [] = [(s, 1)] | |
collect s all@((sym, num):others) | |
| sym == s = (sym, num + 1):others | |
| otherwise = (s, 1):all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment