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
Step: 1
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