Skip to content

Instantly share code, notes, and snippets.

@kh0p
Created September 3, 2013 17:15
Show Gist options
  • Save kh0p/6426750 to your computer and use it in GitHub Desktop.
Save kh0p/6426750 to your computer and use it in GitHub Desktop.
game of life, c implementation
#include <string.h>
#define C(x, y) (z[q][(y)*72+(x)])
#define P(x, y) \
C(x-1,y-1)+C(x,y-1)+C(x+1,y-1)+C(x-1,y)+C(x+1,y)+C(x-1,y+1)+C(x,y+1)+C(x+1,y+1)
char z[2][1728],q=0;main(i,x,y,n){for(i=0;i<1728;++i)z[q][i]=rand()&1;do{memset(
z[q^1],0,1728);for(y=1;y<24-1;++y)for(x=1;x<72-1;++x){n=P(x,y);z[q^1][(y)*72+(x)
]=(C(x,y)&&(n==2||n==3))|(!C(x,y)&&n==3);}q^=1;for(y=0;y<24;++y){for(x=0;x<72;
++x)putchar(C(x,y)[" o"]);putchar(10);}}while(getchar()!=-1);}
/* --anon */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment