"""Verify the nine upper bounds from the accompanying zero-based coordinates.""" import json from pathlib import Path def verify(board): n = board["n"] queens = board["queens"] if board["size"] != n // 2 + 1 or len(queens) != board["size"]: raise ValueError(f"Q{n}: incorrect placement size") for square in queens: if (len(square) != 2 or any(type(v) is not int or not 0 <= v < n for v in square)): raise ValueError(f"Q{n}: invalid coordinate {square}") if len(set(map(tuple, queens))) != len(queens): raise ValueError(f"Q{n}: repeated square") for y in range(n): for x in range(n): if not any(x == c or y == r or abs(x-c) == abs(y-r) for c, r in queens): raise ValueError(f"Q{n}: uncovered square ({x},{y})") print(f"Q{n}: {len(queens)} queens cover all {n*n} squares") if __name__ == "__main__": source = Path(__file__).with_name("witnesses.json") boards = json.loads(source.read_text(encoding="utf-8"))["boards"] if [board["n"] for board in boards] != list(range(66, 83, 2)): raise ValueError("Expected the nine even orders from 66 to 82") for board in boards: verify(board)