Problem #159
Tags:
games
implementation
data-structures
classical
c-1
c-0
This is an advanced version of the Life is Simple problem. Now you are to research the evolution of the long-living colony of cells.
Really, there are even very small initial configurations which came to stable situation only after thousands of moves, for example these two:
- - - - - - - - - - - - - - - - - - - -
- - - X X - - - - - - - X - - - - - - -
- - X X - - - - - - - - - - X - - - - -
- - - X - - - - - - - X X - - X X X - -
- - - - - - - - - - - - - - - - - - - -
They are called r-pentamino
and acorn
. First of them takes 1103
generations before stabilizing and the second
even 5206
. (the stable results in both cases include oscillators and gliders)
On the demo above you can play with both of them being bombed by single glider and watch to which results such an interruption leads.
You are to determine the fate of the combination of acorn
and glider
. The goal is to output two values - how
many generation it took to stabilize and what is the final amount of cells.
Since it is not easy to determine the moment of stabilizing, let us use the following simple criteria:
the total count of cells is not changing since the generation N
for at least 5
moves (i.e. up to generation
N+4
)
Initial configuration is defined simply by realtive position of acorn and glider. Regard the following situation:
- - - - - - - - - - - - - - - - - -
- - - X - - - - - - - - - - - - - -
- - - - X - - - - - - - - - - - - -
- - X X(X)- - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - X - - - - - - -
- - - - - - - - - - - - X - - - - -
- - - - - - - - -(X)X - - X X X - -
- - - - - - - - - - - - - - - - - -
The cells surrounded by parentheses are points of reference. Acorn is placed so its point of reference is at the cell
with coordinates (0,0)
, while the coordinates for the point of refenrence of the glider are given as input data.
For example in the given case they are (-5,5)
.
Input data will contain two coordinates for the position of the glider, as described above.
Answer should contain number of generations to stabilize and the amount of live cells after this.
Example:
input data:
-5 5
answer:
545 35
Clarification: Answer like N P
means that:
N-1
steps from beginning, number of cells was different from P
;N
there are exactly P
cells, and it keeps the same for N+1
, N+2
, N+3
and N+4
generations.