Game of the life (2)

This exercise is a continuation of the exercise problem://problemsjutge.org:problems/p1/roura/vida-1.pbm

Let M0M_0 be a matrix with bacteria at the initial time, and let M1M_1, M2M_2, M3M_3, … be the matrices at the times 1, 2, 3, … Write a program that, given M0M_0, finds the cycle that is obtained starting at M0M_0, that is, the first and shortest sequence of matrices Mi,Mi+1,,Mj1,MjM_i, M_{i+1}, \dots, M_{j-1}, M_j such that Mj+1=MiM_{j+1} = M_i. Suppose j<100j < 100.

Input

Input consists of the description of the matrix M0M_0: two strictly positive natural numbers nn and mm, followed by nn lines, each one with mm characters: ‘B’ if the position has a bacterium, and ‘.’ if the position is empty.

Output

Print the matrices of the cycle Mi,Mi+1,,Mj1,MjM_i, M_{i+1}, \dots, M_{j-1}, M_j separated by an empty line.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:41:53.332Z

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