-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_118.py
45 lines (39 loc) · 1.85 KB
/
task_118.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from arc_tools.grid import Grid, GridPoint, GridRegion, SubGrid
from arc_tools.plot import plot_grid, plot_grids
def row_col_color_data(grid: Grid) -> Grid:
"""
input grid: divide the grid into 4 subgrids
first piece: row
second piece: col
third piece: background color (ratio map)
fourth piece: data
output grid: A grid with row, col, and data else background color (ratio map).
"""
grid.background_color = 0
grid_size = len(grid)
subgrid_size = grid_size//2
# plot_grid(grid, name="input.png", show=True)
first_piece = SubGrid(GridRegion([GridPoint(0, 0), GridPoint(subgrid_size-1, subgrid_size-1)]), grid)
second_piece = SubGrid(GridRegion([GridPoint(subgrid_size, 0), GridPoint(2*subgrid_size-1, subgrid_size-1)]), grid)
third_piece = SubGrid(GridRegion([GridPoint(0, subgrid_size), GridPoint(subgrid_size-1, 2*subgrid_size-1)]), grid)
fourth_piece = SubGrid(GridRegion([GridPoint(subgrid_size, subgrid_size), GridPoint(2*subgrid_size-1, 2*subgrid_size-1)]), grid)
# plot_grids([first_piece, second_piece, third_piece, fourth_piece], show=1, save_all=True)
rows = first_piece.get_total_dots()
cols = second_piece.get_total_dots()
new_grid = []
row_ratio = rows//subgrid_size or 1
col_ratio = cols//subgrid_size or 1
for row in range(rows):
new_row = []
for col in range(cols):
row_idx = row % subgrid_size
col_idx = col % subgrid_size
new_val = fourth_piece[row_idx][col_idx]
if not new_val:
new_val = third_piece[(row//row_ratio)%subgrid_size][(col//col_ratio)%subgrid_size]
new_row.append(new_val)
new_grid.append(new_row)
return Grid(new_grid)
if __name__ == "__main__":
import os
os.system("main.py f931b4a8 row_col_color_data")