Join the social network of Tech Nerds, increase skill rank, get work, manage projects...

• # How to Write Python Code (2.7 version) for the following Problem?

• 0
• 0
• 0
• 0
• 0
• 0
• 0
• 325

Write python code(2.7 version) for the following and also explain the logic because i am not understanding please explain.

Eight houses ,represented as cells , are arranged in a straight line.Each day every cell competes with its adjacent cells(neighbours). An integer value of 1 represents an active cell and a value of 0 represents an inactive cell , the cell becomes inactive on the next day; otherwise the cell becomes active.The two cells on each end have a single adjacent cell ,so assume that the unoccupied space on the opposite side is an inactive cell.Even after updating the cell state , consider its previous state when updating the state of other cells. The state information of all cells should be updated simultaneously.

Write an algorithm to output the state of the cells after the given number of days.

==================================================

Input

The input to the function/method consists of two arguments:

states , a list of integers representing the current state of cells ;

days ; an integer representing the number of days.

Output

Return a list of integers representing the state of the cells after the given number of days.

Note

The elements of the list states contains 0s and 1s only.

TESTCASES 1:
INPUT:
[1,0,0,0,0,1,0,0],1
EXPECTED RETURN VALUE:
[0,1,0,0,1,0,1,0]

TESTCASE 2:
INPUT:
[1,1,1,0,1,1,1,1,],2
EXPECTED RETURN VALUE:
[0,0,0,0,0,1,1,0]

==================================================================

def cellCompete(states,days):

#write your code logic with explanation

pass

OR
OR
Register

OR
Fill out the form below and instructions to reset your password will be emailed to you:

• Hire
• Post Projects

### Post Projects

• All at 0 Cost ....
• Post Tech Job
• Select Best Bidder
• Track the Project
• Approve Work and Pay safely
• Browse Nerds
• Work
• Find Projects Find Projects
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
View more...
View less...
• Manage
• Company Company

### Manage Company

• All at 0 Cost ....
• Manage Company and Employee Profiles
• Company wide Employee Productivity Reports
• Knowledge Sharing and Collaboration Tools
• Get Sales Lead and Bid for Tech Projects
• Send Invoices and Receive Payment Safely
• Learn
• Nerd Digest Nerd Digest
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
View more...
View less...
• Tech Q & A Tech Q & A
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
View more...
View less...