def __init__(self, id_num): """ @todo Document Tile.__init__ (along with arguments). arg - @todo Document argument arg. """ self._id_num = id_num self._shared_edges = [] Grid.__init__(self)
def __str__(self): string = f'Tile {self._id_num}:\n' string += Grid.__str__(self) return string
def get_basin(grid, x, y, basin, visited): visited.append((x, y)) if grid[x, y] == '9': return else: basin.append(grid[x, y]) spaces_to_check = [(x - 1, y), (x, y - 1), (x + 1, y), (x, y + 1)] for s in spaces_to_check: if s in grid and s not in visited: get_basin(grid, s[0], s[1], basin, visited) grid = Grid() grid.build(sys.stdin.read().strip()) low_points = [] basin_sizes = [] visited = [] for x in range(grid.width): for y in range(grid.height): if grid[x, y] < min(grid.get_adjacent(x, y)): low_points.append(grid[x, y]) basin = [] get_basin(grid, x, y, basin, visited) basin_sizes.append(len(basin)) risk_level_sum = sum([int(x) + 1 for x in low_points])
def get_over_ten(grid): over_ten = [] for key, value in grid.items(): if value > 9: over_ten.append(key) return over_ten def step(grid): for x in range(grid.width): for y in range(grid.height): grid[x, y] = int(grid[x, y]) + 1 grid = Grid() grid.build(sys.stdin.read()) print(grid) total_flashes = 0 def entire_step(grid): step(grid) flash_list = [] # Get list of squares that can flash for _ in range(25):
def __init__(self): Grid.__init__(self)