Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
8-liner: using set solution in Clear category for Dangerous Bishops by przemyslaw.daniel
from itertools import product
def safe_squares(n: int, bishops: tuple[int, int]) -> int:
board = product(range(n), repeat=2)
threat = {(x, y) for x, y in board for xb, yb in bishops
if xb - yb == x - y or xb + yb == x + y}
return n ** 2 - len(threat)
Dec. 29, 2023