A Colony of Eight Houses Represented as Cells Python

There is a colony of eight cells arranged in a straight line where each day every cell competes with its adjacent cells(neighbours). Each day, for each jail cell, if it'south neighbours are both active or both inactive, the cell becomes inactive the next mean solar day, otherwise it becomes active the adjacent 24-hour interval.

The ii cells at the ends have only single next jail cell, then the other imaginary adjacent cell can be causeless to be always inactive.

On a given day, even afterward updating the prison cell state, consider it's previous day'south state for updating the country of other cells.

Complete the role cellComplete which takes an eight chemical element array of integer cells representing the current state of viii cells and an integer D days representing the number of days to simulate.

An integer value of one represents an agile cell and value of 0 represents an inactive cell.

Input Format:
The first line contains eight integer values representing the initial state of the cells.
The second line contains D - which represents the number of days.

Output Format:
The offset line contains the state of the cells after D days.

Purlieus Conditions:
1 <= D <= m

Case Input/Output i:
Input:
i 0 0 0 0 1 0 0
3

Output:
0 0 ane 1 i 0 1 0

Example Input/Output 2:
Input:
one 0 0 0 0 1 0 0
ii

Output:
1 0 1 i 0 0 0 1

python:

def cellCompete(c,d):

for _ in range(d):
for i in range(eight):
                n=c[i]

                if i>0 and i<7:

                    c[i]=0 if c[i+ane]==a else ane

                elif i==0:

c[i]=0 if c[i+ane]==0 else one

else:

c[i]=0 if a==0 else 1

a=due north

render c;

cells = [ int (x) forx in input().split()]

days = int (input())

print(*cellCompete(cells,days))

stampcancest2002.blogspot.com

Source: https://codeforalls.blogspot.com/2017/08/complete-cell-state-after-d-days.html

0 Response to "A Colony of Eight Houses Represented as Cells Python"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel