begin 
     comment Game of Life;

   integer array table[0:2,0:2];

   procedure initialisetable (table, M,N);
      integer array table;
        integer M,N;
   begin
      integer i,j;
      for i ≔  step 1 until (M-1) do
           for j ≔  step 1 until (N-1) do
            begin
               if (i ≠ j) then
                 table[i,j] ≔ 0
               else
                 table[i,j] ≔ ;

            end

   end;

   procedure printtable (table,M,N);
      integer array table;
        integer M,N;
   begin
      integer i,j;
      for i ≔  step 1 until M-1 do
         begin
            for j ≔  step 1 until N-1 do
               begin
                  outinteger(1, table[i,j]);
               end;
            outstring(1, “\n”)
         end
   end;      


     procedure applyRules (table, M,N);
      integer array table;
        integer M,N;
   begin
      integer Neighbours,actual,i,j;
      integer array prevGen[0:2,0:2];
      copytable(prevGen,table,M,N);

      for i ≔  step 1 until M-1 do
         begin
            for j ≔  step 1 until N-1 do
               begin
                  actual ≔ prevGen[i,j];
                  countNeighboursAlive (prevGen,M,N,i,j,Neighbours);
                  if (actual = 1) then
                  begin
                     if (Neighbours < 2) then
                       table[i,j] ≔  
                       else
                     if (Neighbours ⩽ 3) then
                       table[i,j] ≔ 
                     else 
                       table[i,j] ≔ ;            
                    end
                    else
                  if (Neighbours = 3) then table[i,j] ≔ ;

               end;
         end

   end;

   procedure countNeighboursAlive (table, M,N, x,y, Neighbours);
      value M,N,x,y;
      integer array table;
        integer M,N,x,y,Neighbours;
   begin
      boolean isNeighbour;
      integer i,j;
      Neighbours ≔ 0;
      for i ≔ x-1) step 1 until (x+1) do
         begin
            for j ≔ y-1) step 1 until (y+1) do
               begin
                  isNeighbour ≔ (   (i⩾0) ∧ (j⩾0) ∧ (i<M) ∧ (j<N) ∧ ( (x ≠ i) ∨ (y ≠ j) )   );
                  if  isNeighbour then
                  begin
                     if (table[i,j] = 1) then Neighbours ≔ Neighbours +1
                  end

               end;
         end


   end;

   procedure copytable (prevGen,table,M,N);
   begin
      integer i,j;
      for i ≔  step 1 until (M-1) do
           for j ≔  step 1 until (N-1) do
              prevGen[i,j] ≔ table[i,j];

   end;

   initialisetable(table,3,3);
   printtable(table,3,3);
   applyRules(table,3,3);
   printtable(table,3,3);

end