def gray_code(N):
    """ Generate a Gray code for traversing the N qubit states. """
    if N <= 0 or type(N) is not int:
        raise ValueError("Input for gray code construction must be a positive integer.")
    if N == 1: # Base case
        return ["0", "1"]
    else:
        sub_code = gray_code(N-1)
        return ["0" + x for x in sub_code] + ["1" + x for x in sub_code[::-1]]