#include <stdio.h>
#include <stdlib.h>
char map[5][5];
void next_turn(void)
{
int i,j;
char k;
for(i=0;i<5;i++) {
for(j=0;j<5;j++) {
k=0;
k+=map[((i+1)%5)][j];
k+=map[((i+4)%5)][j];
k+=map[i][((j+1)%5)];
k+=map[i][((j+4)%5)];
if(k==2 || k==3) {
/* 1 xor 1 = 0 , 0 xor 0 = 0 */
map[i][j]^=map[i][j];
}
}
}
}
int main(void)
{
int i,j;
/* creat map */
for(j=0;j<5;j++) {
i
=(int)(((double)rand() / ((double)RAND_MAX
+1.0)) * 32); map[j][0]= 0x01 & i;
map[j][1]= 0x01 & (i>>1);
map[j][2]= 0x01 & (i>>2);
map[j][3]= 0x01 & (i>>3);
map[j][4]= 0x01 & (i>>4);
}
for(j=0;j<10;j++) {
next_turn();
}
for(j=0;j<5;j++) {
printf("%d%d%d%d%d\n",map
[j
][0],map
[j
][1],map
[j
][2],map
[j
][3],map
[j
][4]); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KY2hhciBtYXBbNV1bNV07CnZvaWQgbmV4dF90dXJuKHZvaWQpCnsKICAgIGludCBpLGo7CgljaGFyIGs7Cglmb3IoaT0wO2k8NTtpKyspIHsKCQlmb3Ioaj0wO2o8NTtqKyspIHsKCQkJaz0wOwoJCQlrKz1tYXBbKChpKzEpJTUpXVtqXTsKCQkJays9bWFwWygoaSs0KSU1KV1bal07CgkJCWsrPW1hcFtpXVsoKGorMSklNSldOwoJCQlrKz1tYXBbaV1bKChqKzQpJTUpXTsKCgkJCWlmKGs9PTIgfHwgaz09MykgewovKiAxIHhvciAxID0gMCAsIDAgeG9yIDAgPSAwICovCgkJCQltYXBbaV1bal1ePW1hcFtpXVtqXTsKCQkJfQoJCX0KCX0KfQoKaW50IG1haW4odm9pZCkKewoJaW50IGksajsKCi8qIGNyZWF0IG1hcCAqLwoJZm9yKGo9MDtqPDU7aisrKSB7CgkJaT0oaW50KSgoKGRvdWJs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