Jump to content

99 Elm Problems/Problem 9/Solutions

From Wikibooks, open books for an open world

Solution 1: Recursive version

pack list =
    case list of
        [] -> []
        [ x ] -> [ [ x ] ]
        x :: xs ->
            case pack xs of
                [] -> []
                x' :: xs' ->
                    if List.member x x' then
                        (x :: x') :: xs'
                    else
                        [ x ] :: x' :: xs'