99 Elm Problems/Problem 10
Run-length encode a list of tuples. Output runs of equal elements as tuples (n, e)
where n
is the number of duplicates of the element e
.
import Html exposing (text)
import List
runLengthEncode : List a -> List (a, Int)
-- your implementation goes here
main = text <| toString <|
runLengthEncode [1, 1, 1, 2, 3, 3, 3, 4, 4, 4, 4, 5, 6, 6]
Result:
[ ( 1, 3 ), ( 2, 1 ), ( 3, 3 ), ( 4, 4 ), ( 5, 1 ), ( 6, 2 ) ]