Problem 49 Solutions

Solution 1

grayCodes : Int -> List (List Int)
grayCodes numBits =
    let
        n =
            max 0 numBits
    in
        case n of
            0 ->
                []

            1 ->
                [ [ 0 ], [ 1 ] ]

            _ ->
                let
                    n =
                        abs numBits

                    xs =
                        grayCodes (n - 1)
                in
                    (List.map ((::) 0) xs) ++ (List.map ((::) 1) (List.reverse xs))

Back to problem

results matching ""

    No results matching ""