79 lines
1.8 KiB
Python
79 lines
1.8 KiB
Python
"""
|
|
name: Nicholas Tamassia
|
|
|
|
Honor Code and Acknowledgments:
|
|
|
|
This work complies with the JMU Honor Code.
|
|
|
|
Comments here on your code and submission.
|
|
"""
|
|
|
|
import typing
|
|
|
|
import numpy as np
|
|
|
|
type SquareGrid = np.ndarray[tuple[int, int], np.dtype[np.int64]]
|
|
|
|
|
|
def tile(grid: SquareGrid, hole: tuple[int, int]) -> None:
|
|
|
|
tile_index = 0
|
|
grid[hole] = -1
|
|
|
|
def recurse(size: int, top: int, left: int, hole: tuple[int, int]) -> None:
|
|
if size == 1:
|
|
return
|
|
|
|
half = size // 2
|
|
|
|
center_row, center_col = top + half, left + half
|
|
|
|
centers = [
|
|
(center_row - 1, center_col - 1),
|
|
(center_row - 1, center_col),
|
|
(center_row, center_col - 1),
|
|
(center_row, center_col),
|
|
]
|
|
|
|
quadrant: int = 0
|
|
|
|
if hole[0] >= center_row:
|
|
quadrant += 2
|
|
if hole[1] >= center_col:
|
|
quadrant += 1
|
|
|
|
nonlocal tile_index
|
|
for q, center in enumerate(centers):
|
|
if q != quadrant:
|
|
grid[center] = tile_index
|
|
|
|
tile_index += 1
|
|
|
|
centers[quadrant] = hole
|
|
|
|
recurse(half, top, left, centers[0])
|
|
recurse(half, top, center_col, centers[1])
|
|
recurse(half, center_row, left, centers[2])
|
|
recurse(half, center_row, center_col, centers[3])
|
|
|
|
recurse(grid.shape[0], 0, 0, hole)
|
|
|
|
|
|
# All modules for CS 412 must include a main method that allows it
|
|
# to imported and invoked from other python scripts
|
|
def main():
|
|
n: int = int(input())
|
|
x, y = map(int, input().split())
|
|
|
|
grid: SquareGrid = np.zeros((2**n, 2**n), dtype=np.int64)
|
|
|
|
tile(grid, (x, y))
|
|
|
|
for row in grid:
|
|
row_list = typing.cast(list[int], row.tolist())
|
|
print(" ".join(map(lambda x: f"{x:02d}", row_list)))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|