Problem 19 Solution

{-| rotate the elements of a list, negative count rotates in the opposite direction
-}
rotate : Int -> List a -> List a
rotate n list =
    case list of
        [] ->
            []

        _ ->
            let
                r =
                    n % (List.length list)
            in
                List.drop r list ++ List.take r list

Back to problem

results matching ""

    No results matching ""