Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- int world[2048];
- int O = (int)&O;
- int i;
- // bit 5 (=32) of world[i] is old cell state
- // bit 4 (=16) of world[i] is new cell state
- // World contains 64 columns, 32 rows
- for(i = 0; i < 2048; ++i)
- {
- O = (O*0x41C64E6D + 12345) & 0x7fffffff;
- world[i] = (O & 1024) ? 32 : 0;
- }
- usleep(102400);
- for(;;)
- {
- for(i = 0; i < 2048; ++i)
- {
- // For each neighbor, increase world[i]. This is at max 8 = 2**3, so this won't affect bits 4 and 5.
- const int diffNeighbor[4] = {1, 63, 64, 65};
- int j;
- for (j = 0; j < 4; ++j)
- {
- if(world[(i + diffNeighbor[j]) % 2048] & (1 << 5))
- {
- ++world[i];
- }
- if(world[(i - diffNeighbor[j]) % 2048] & (1 << 5))
- {
- ++world[i];
- }
- if(j==3)
- {
- // Apply "game of life" rule.
- world[i] |= ((world[i] ^ 34) && (world[i] ^ 35)) ? ( (world[i]^3) ? 0 : (1<<4)) : (1<<4);
- }
- }
- }
- for (i = 1; i < 2048; ++i)
- {
- world[i] = ( world[i] & (1 << 4) ) << 1; // set new call state from old state
- putchar(world[i] ? 'X':' ');
- if((i-1)%64==0) //if(!(63^i % 64))
- {
- putchar('\n');
- }
- }
- usleep(102400);
- }
- }
Add Comment
Please, Sign In to add comment