Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

99 Elm Problems/Problem 11

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Write a function to run length encode a list, but instead of using a tuple as in problem 10, define a data type that can represent either a single element or a run of multiple identical element. import Html exposing (text) import List type Item a = Single a | Multiple Int a runLengthEncode : List a -> List (Item a) -- your implementation goes here main = text <| toString <| runLengthEncode ['a', 'a', 'a', 'b', 'c', 'c', 'd', 'e', 'e', 'e', 'e', 'e'] Result: [Multiple 3 'a', Single 'b', Multiple 2 'c', Single 'd', Multiple 5 'e'] Solutions