Задача 5E. Game of Life with Numpy

Входной файл:Стандартный вход   Ограничение времени:1 сек
Выходной файл:Стандартный выход   Ограничение памяти:512 Мб

Условие

Требуется реализовать на языке Python класс GameOfLife. Класс описывает обобщённую игру «Жизнь». Игра представляет собой многомерный (n >= 2) массив булевых значений. Каждая ячейка может быть живой (True) или мёртвой (False). На каждой итерации состояние игры обновляется следующим образом:

Соседями граничных клеток являются соответствующие граничные клетки с противоположной стороны измерения. У класса должен быть следующий интерфейс:

import numpy as np

class GameOfLife:
    '''Represents a generalized Conway's Game of Life.
    The game is an n-dimensional array (n >= 2) of boolean values. Each cell is either alive (True) or dead (False).
    On each iteration the cells are updated as follows:
        - An alive cell stays alive if it has between `a` and `b` live neighbours
        - A dead cell becomes alive if it has between `c` and `d` live neighbours
        - Otherwise a cell dies
    The board has wraparound edges, so the neighbours of edge cell are located on the opposite edge.

    Fields:
        board: the current state of the game, n-dimensional array of type bool
        a: minimal number of live neighbours for a cell to stay alive
        b: maximal number of live neighbours for a cell to stay alive
        c: minimal number of live neighbours for a cell to become alive
        d: maximal number of live neighbours for a cell to become alive
    '''

    def __init__(self, board: np.ndarray,
                 a: int = 2, b: int = 3,
                 c: int = 3, d: int = 3):
        '''Initializes `board` and game rule fields. `board` must be stored as a copy'''
        pass

    def next_iteration(self) -> None:
        '''Computes the next iteration of the game. Invalidates `self.board`'''
        pass

Формат выходных данных

Код решения должен содержать только определение и реализацию класса.


0.051s 0.009s 13