Created
August 14, 2016 08:33
-
-
Save samidarko/27c9abb566e3c5cd2717e1e838e7726e to your computer and use it in GitHub Desktop.
Count the number of occurrences in a string over consumption
This file contains hidden or 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 qualified Data.Char as Char | |
| countOccurrences :: String -> String | |
| countOccurrences "" = "" | |
| countOccurrences s = let (fw, rest) = span (\x -> x == head s) s in (Char.intToDigit $ length $ fw) : (head s) : (countOccurrences rest) | |
| countOccurrences "aaaaabbbbccccccaaaaaaa" | |
| -- "5a4b6c7a" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment