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 . . . .BBBB
. . . B . . . B.BBBB.
B . . . . . . BB.B.B.
. . . . . B . B. . .BBB
. . . . . . . . . . . .B.

 

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

 

Example 3
Inital state       After 1 cycle (new cells in boldface)
. . . . . . .B.B. .
. B . B . . BBBBB.
B . . . . . BB.B.B
. . . . . B B. . .BB
. . . . . B . . . .BB
. . . . . . . . . . .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-05-08T13:46:45.020Z

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