def edge(i, j, v):
    """Determines if a point at i, j in a boolean grid v is on the boundary."""
    try:
        if v[i - 1, j] and v[i + 1, j] and v[i, j - 1] and v[i, j + 1]:
            return False
        else:
            return True
    except:
        return True
