Question: python 3.6 count_neighbors(grid, r, c): Given a Grid and two integers indicating row/column position, count how many living neighbors there are. When a cell is

python 3.6

count_neighbors(grid, r, c): Given a Grid and two integers indicating row/column position, count how many living neighbors there are. When a cell is on the edge or corner of our Grid , treat all non-existent neighbor positions as dead (they don't contribute to the returned count).

o Assume: grid is a Grid; live and dead are strings of length one.

o Hint: Use your on_grid definition!

o Examples all use the grid g drawn to the right.

g: count_neighbors(g, 0, 0)0

count_neighbors(g, 0, 4)1

count_neighbors(g, 2, 4)2

count_neighbors(g, 3, 2)2

count_neighbors(g, 2, 3)5

where g is a 2D grid

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!