跳到内容

99 道 Elm 难题/难题 9/解答

来自维基教科书,一个开放世界的开放书籍

解答 1:递归版本

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'
华夏公益教科书