Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
improved fill_diagonal solution in 3rd party category for Dangerous Bishops by juestr
import numpy as np
def safe_squares(n: int, bishops: list[tuple[int, int]]) -> int:
if not bishops:
return n * n
board = np.ones(shape=(n, n), dtype=bool)
rows, cols = np.array(bishops).T
for board, cols in [(board, cols), (np.fliplr(board), n - 1 - cols)]:
for d in set(cols - rows):
np.fill_diagonal(board[:, d:] if d >= 0 else board[-d:, :], False)
return np.sum(board)
May 24, 2024
Comments: