74 lines
1.7 KiB
Python
74 lines
1.7 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 numpy as np
|
||
|
|
|
||
|
|
|
||
|
|
def tile(grid: np.ndarray, 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: np.ndarray = np.zeros((2**n, 2**n), dtype=int)
|
||
|
|
|
||
|
|
tile(grid, (x, y))
|
||
|
|
|
||
|
|
for row in grid:
|
||
|
|
print(" ".join(map(lambda x: f"{x:02d}", row)))
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|