# Problem Description
This is a grid pattern generation problem where we need to:
- Create an n×n grid (where n is always odd)
- Place black cells (represented as 1) in specific positions
- Fill remaining cells with white (represented as 0)
- Return the resulting grid as a 2D matrix
- The pattern follows a specific rule of expansion as n increases

# Visual Facts
1. Grid Properties:
   - Each grid is n×n where n is odd (1, 3, 5, 7, 9, 11)
   - Each step adds 2 to n, creating a new outer ring

2. Cell States:
   - Cells are either black (filled) or white (empty)
   - For n=1: no black cells
   - For n=3: four black cells
   - For n=5: four black cells
   - For n=7: eight black cells
   - For n=9: eight black cells
   - For n=11: twelve black cells

# Visual Patterns
A cell at position [i][j] is black when it's a corner of an odd ring: |i-n//2| = |j-n//2| = 1+2k where k ≥ 0

This means black cells appear at:
- Positions where distance from center (in both x and y) is equal and is a odd number

All other cells are white.

This explains:
- n=1: no black cells
- n=3: four cells at distance 1
- n=5: four cells at distance 1
- n=7: four cells at distance 1 + four cells at distance 3
- n=9: four cells at distance 1 + four cells at distance 3
- n=11: four cells at distance 1 + four cells at distance 3 + four cells at distance 5


# Solution
from typing import List

def solution(n: int) -> List[List[int]]:
    """
    Given an n x n grid, determine the coordinates of a specific pattern that is formed on the grid. 
    
    Parameters:
        n (int): The dimensions of the grid (which is an n*n 2D matrix). n is always an odd number.
    
    Returns:
        List[List[int]]: A n*n 2D matrix where the coordinates of the black cells are marked with 1 and the rest are marked with 0.
    """
    grid = [[0 for _ in range(n)] for _ in range(n)]
    
    # Middle index
    mid = n // 2
    
    # Set the center
    grid[mid][mid] = 0
    
    # Set the diagonals
    for i in range(mid + 1):
        if (i-mid) % 2 == 0:
            continue
        grid[i][i] = 1
        grid[i][n - 1 - i] = 1
        grid[n - 1 - i][i] = 1
        grid[n - 1 - i][n - 1 - i] = 1
    
    return grid


# Test Script
def reference(n):
    grid = [[0 for _ in range(n)] for _ in range(n)]
    
    # Middle index
    mid = n // 2
    
    # Set the center
    grid[mid][mid] = 0
    
    # Set the diagonals
    for i in range(mid + 1):
        if (i-mid) % 2 == 0:
            continue
        grid[i][i] = 1
        grid[i][n - 1 - i] = 1
        grid[n - 1 - i][i] = 1
        grid[n - 1 - i][n - 1 - i] = 1
    
    return grid

def test():
    test_cases = [n for n in range(3, 40, 4)]
    
    for n in test_cases:
        try:
            output = solution(n)
            expected_output = reference(n)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`n`: {n}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message
            
        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`n`: {n}\n\n"
                f"Actual Output (grid):\n"
                f"{'\n'.join([str(row) for row in output])}\n\n"
                f"Expected Output (grid):\n"
                f"{'\n'.join([str(row) for row in expected_output])}"
            )
            assert False, error_message

test()