#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
  double p, q;
  int N;
  int * x, *y, *z;
  int * X, *Y, *Z;
  int i;
  int t, T, TRANS;
  double tau[2][2];
  double m, summ;
  double h, sumh;
  double r;
  
  srand48(time(NULL));
  
  N = 100;
  T = 100;
  TRANS=10000;

 

  x = calloc(N+1, sizeof(int));
  y = calloc(N+1, sizeof(int));
  X = calloc(N+1, sizeof(int));
  Y = calloc(N+1, sizeof(int));
  
  
  for (q=0; q<=1; q+= 0.05) {
    for (p=0; p<=1; p+= 0.05) {
      tau[0][0]=0;
      tau[0][1]=tau[1][0] = p;
      tau[1][1]= q;
      summ=0;
      sumh=0;
      for (i=0; i<N; i++) {
        x[i] = drand48() < 0.5? 1 : 0;
        X[i] = drand48() < 0.5? 1 : 0;
      }
      for (t=0; t<T+TRANS; t++) {
        x[N] = x[0]; // boundary conditions
        X[N] = X[0]; // boundary conditions
        for (i=0; i<N; i++) {
          r = drand48();
          y[i] = r < tau[x[i]][x[i+1]] ? 1 : 0;
          Y[i] = r < tau[X[i]][X[i+1]] ? 1 : 0;
        }
        z = x;
        x = y;
        y = z;
        Z = X;
        X = Y;
        Y = Z;

        m = 0; 
        for (i=0; i<N; i++) {
          m += x[i];
        }
        if (t>TRANS) {
          summ += m/N;
        }
        h = 0; 
        for (i=0; i<N; i++) {
          h += (x[i] != X[i]);
        }
        if (t>TRANS) {
          sumh += h/N;
        }
     }
      printf("%f %f %f %f\n", p, q, summ/T, sumh/T);
    }
  }
}