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

int main() {
  double p, q;
  int N;
  int * x, *y, *z;
  int i;
  int t, T;
  double tau[2][2];
  double m;
  
  srand48(time(NULL));
  
  N = 1000;
  p = q = 0.65;
  T = 1000;

  tau[0][0]=0;
  tau[0][1]=tau[1][0] = p;
  tau[1][1]= q;
 

  x = calloc(N+1, sizeof(int));
  y = calloc(N+1, sizeof(int));
  for (i=0; i<N; i++) {
    x[i] = drand48() < 0.5? 1 : 0;
  }
  for (t=0; t<T; t++) {
    x[N] = x[0]; // boundary conditions
    for (i=0; i<N; i++) {
      y[i] = drand48() < tau[x[i]][x[i+1]] ? 1 : 0;
    }
    z = x;
    x = y;
    y = z;

    m = 0; 
    for (i=0; i<N; i++) {
      m += x[i];
    }
    printf("%f %f %f\n", p, q, m/N);
  }
}