Game of the life (2)

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

Let M₀ be a matrix with bacteria at the initial time, and let M₁, M₂,
M₃, … be the matrices at the times 1, 2, 3, … Write a program that,
given M₀, finds the cycle that is obtained starting at M₀, that is, the
first and shortest sequence of matrices
M_(i), M_(i + 1), …, M_(j − 1), M_(j) such that M_(j + 1) = M_(i).
Suppose j < 100.

Input

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

Output

Print the matrices of the cycle M_(i), M_(i + 1), …, 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
