function game(n,m,t)

B = round(rand(n,m));
for time=1:t
  A = B;
  for i=1:n
    for j=1:m
        cola = [i-1,i,i+1];
        cola(cola<1) = n;
        cola(cola>n) = 1;
        colb = [j-1,j,j+1];
        colb(colb<1) = m;
        colb(colb>m) = 1;       
      R=sum(sum(A(cola,colb)));

      B(i,j) = ((R==3 || R==4) && A(i,j)) || ( R==3 && ~B(i,j));
    end
  end
  spy(B);
  pause(0.05);
end

