Prokaryote Growths (1)

A petri dish is represented as a grid of size N×MN\times{M}, where:

At each growth cycle, each bacterium spreads to its neighboring cells in horitzontal and vertical directions (i.e., up, down, left, right).

Write a function growth_cycle(grid) that, given an N×MN\times{M} matrix representing the initial state of the colony, returns the state of the petri dish after one growth cycle.

EXAMPLES

Example 1
Inital state       After 1 cycle (new cells in boldface)
. . . . . B . . . . B B B B
. . . B . . . B . B B B B .
B . . . . . . B B . B . B .
. . . . . B . B . . . B B B
. . . . . . . . . . . . B .

 

Example 2
Inital state       After 1 cycle (new cells in boldface)
. . . . . . . . . . . B . . . .
. . . B . . . . . . B B B . . .
. . . B . . . . B . B B B . . .
B . . . . . . . B B . B . . . .

 

Example 3
Inital state       After 1 cycle (new cells in boldface)
. . . . . . . B . B . .
. B . B . . B B B B B .
B . . . . . B B . B . B
. . . . . B B . . . B B
. . . . . B . . . . B B
. . . . . . . . . . . B

Observation

Important: Submit only the function. If you have a main program, comment it out or embed it inside a conditional clause if __name__ == "__main__":

Problem information

Author: Lluís Padró

Generation: 2026-01-25T13:14:52.714Z

© Jutge.org, 2006–2026.
https://jutge.org