Created
June 2, 2014 02:15
-
-
Save larryv/77a15a2dae215fa12c17 to your computer and use it in GitHub Desktop.
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
def times(chars: List[Char]): List[(Char, Int)] = { | |
def incr(pairs: List[(Char, Int)], C: Char): List[(Char, Int)] = | |
pairs match { | |
case Nil => List((C, 1)) | |
case (C, n) :: ps => (C, n+1) :: ps | |
case p :: ps => p :: incr(ps, C) | |
} | |
(chars foldLeft List[(Char, Int)]())(incr) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment