Ejemplo n.º 1
0
def _flash(grid: IntGrid, c: Cell, flashes: Flashes) -> None:
    grid.set_value(c, 0)
    flashes.increment()
    for n in _find_neighbours(grid, c):
        if grid.get_value(n) == 0:
            continue
        grid.increment(n)
        if grid.get_value(n) > 9:
            _flash(grid, n, flashes)
Ejemplo n.º 2
0
def _cycle(grid: IntGrid) -> int:
    [grid.increment(c) for c in grid.get_cells()]
    flashes = Flashes()
    [
        _flash(grid, c, flashes) for c in grid.get_cells()
        if grid.get_value(c) > 9
    ]
    return flashes.get()
Ejemplo n.º 3
0
def _size_of_basin_around_low(grid: IntGrid, c: Cell) -> int:
    basin = set[Cell]()
    q = deque[Cell]()
    q.append(c)
    while len(q) > 0:
        cell = q.popleft()
        basin.add(cell)
        for n in _find_neighbours(grid, cell):
            if n not in basin and grid.get_value(n) != 9:
                q.append(n)
    log(basin)
    log(len(basin))
    return len(basin)
Ejemplo n.º 4
0
def _find_lows(grid: IntGrid) -> Generator[Cell]:
    for low in (c for c in grid.get_cells() if (all(
            grid.get_value(c) < grid.get_value(n)
            for n in _find_neighbours(grid, c)))):
        log(low)
        yield low