(mapping)
return terminal_states
Given a 1D array interpreted as a function
    :math:`f : \\{0, \\ldots, n - 1\\}} \to \\{0, \\ldots, n - 1\\}}`, such
    that :math:`f^{(k)} = f^{(k + 1)}` for some :math:`k`, find the 1D array
    corresponding to :math:`f^{(k)}`.
Given a 1D array interpreted as a function
    :math:`f : \\{0, \\ldots, n - 1\\}} \to \\{0, \\ldots, n - 1\\}}`, such
    that :math:`f^{(k)} = f^{(k + 1)}` for some :math:`k`, find the 1D array
    corresponding to :math:`f^{(k)}`.
Given a 1D array interpreted as a function : math : f : \\ { 0 \\ ldots n - 1 \\ }} \ to \\ { 0 \\ ldots n - 1 \\ }} such that : math : f^ { ( k ) } = f^ { ( k + 1 ) } for some : math : k find the 1D array corresponding to : math : f^ { ( k ) } .
def _limit_mapping(mapping):
    """Given a 1D array interpreted as a function
    :math:`f : \\{0, \\ldots, n - 1\\}} \to \\{0, \\ldots, n - 1\\}}`, such
    that :math:`f^{(k)} = f^{(k + 1)}` for some :math:`k`, find the 1D array
    corresponding to :math:`f^{(k)}`."""
    terminal_states = np.empty_like(mapping)
    for i, initial_target_idx in enumerate(mapping):
        temp_target_idx = i
        next_target_idx = initial_target_idx
        while temp_target_idx != next_target_idx:
            temp_target_idx = mapping[temp_target_idx]
            next_target_idx = mapping[mapping[temp_target_idx]]
        terminal_states[i] = temp_target_idx

    return terminal_states
def _limit_mapping ( mapping ) : terminal_states = np . empty_like ( mapping ) for i , initial_target_idx in enumerate ( mapping ) : temp_target_idx = i next_target_idx = initial_target_idx while temp_target_idx != next_target_idx : temp_target_idx = mapping [ temp_target_idx ] next_target_idx = mapping [ mapping [ temp_target_idx ] ] terminal_states [ i ] = temp_target_idx return terminal_states