Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Given a grid with n rows and m columns of binary integers, 0 or 1, and a set of rules, simulate k turns of
Given a grid with n rows and m columns of binary integers, 0 or 1, and a set of rules, simulate k turns of the game on this grid. The given grid denotes the initial configuration for the game, where grid[i] [] = 1 denotes that cell in the throw and th column is alive, and grid[i] = 0 denotes that this cell is dead. Two cells are neighbors when they share at least one common corner, thus each cell has at most 8 neighbors, as shown in the picture below: There is a list of 9 rules indexed from 0 to 8, each rule having a value of either 'alive' or 'dead'. A single rule, let's say rule i, specifies what happens to the cells with exactly i alive neighbors. In each turn, the new value of a cell is determined by counting the number of "alive' neighbors and applying the rule at index corresponding to the count. As an example, consider a rule set where rules at indices 3 and 5 are 'alive'. All of the other rules are dead. The following shows the process for two turns starting with the grid given in turn 0: Turn 0 Grid 0110 1100 White cell with 8 neighbors 1100 0110 0110 1100 Live neighbors for each cell 3321 2331 2331 3321 The "Live neighbors for each cell" grid at turn 7 contains the number of adjoining live cells at each grid position for turn 0. It is used to create the new grid state for turn 7. At each cell with a value of 3 or 5, the David Paul Th X top Washington Post: B... Python 3 TTTT AWNINGSAWNHO 1 >#!/bin/python3... 10 1 11 # 14 15 16 17 18 19 # 20 (5) Alan Watts-Outw x NA 22 23 24 > if 21 def gridGame (grid, k, rules): #Write your code here name Test Results The New York Time... DeviantArt-Discov... 12 # Complete the 'gridGame function below. 13 # # The function is expected to return a 2D_INTEGER ARRAY. # The function accepts following parameters: # 1. 2D INTEGER ARRAY grid # 2. INTEGER k # 3. STRING ARRAY rules AUDUSD 0.65063 A Autocomplete Ready O I main X Custom Input (5) Trading View Forex x Netflix Stocktwits-The lar..... M Medium-Get smar.....
Step by Step Solution
★★★★★
3.41 Rating (154 Votes )
There are 3 Steps involved in it
Step: 1
The gridGame function is written as follows The funct...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started