from operator import mod


def generate_other(probe:int, limit:int, flags:list, *, inverse:bool=True, forward:bool=True) -> list:
    """
    Generate indices of other locations for given probe location, limit range and flags.


    Parameters
    ----------
    probe: int
        probe index
    limit: int
        maximum distance from the probed location
    flags: list
        virtual/monitor flags 0/1 for each location
    inverse: bool
        flag to move in the inverse direction
    forward: bool
        flag to move in the forward direction

    Returns
    -------
    other (list)

    """
    other = []
    total = len(flags)

    local = []
    index = probe
    while inverse:
        index -= 1
        if flags[int(mod(index, total))] == 1:
            local.append(index)
        if len(local) == limit:
            break
    other.extend(reversed(local))

    local = []
    index = probe
    while forward:
        index += 1
        if flags[int(mod(index, total))] == 1:
            local.append(index)
        if len(local) == limit:
            break
    other.extend(local)

    return other