Guest User

https://github.com/duckythescientist/obfuscatedLife

a guest
Nov 26th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. int main()
  2. {
  3.     int world[2048];
  4.     int O = (int)&O;
  5.     int i;
  6.    
  7.     // bit 5 (=32) of world[i] is old cell state
  8.     // bit 4 (=16) of world[i] is new cell state
  9.     // World contains 64 columns, 32 rows
  10.  
  11.     for(i = 0; i < 2048; ++i)
  12.     {
  13.         O = (O*0x41C64E6D + 12345) & 0x7fffffff;
  14.         world[i] = (O & 1024) ? 32 : 0;
  15.     }
  16.  
  17.     usleep(102400);
  18.     for(;;)
  19.     {
  20.         for(i = 0; i < 2048; ++i)
  21.         {
  22.             // For each neighbor, increase world[i]. This is at max 8 = 2**3, so this won't affect bits 4 and 5.
  23.             const int diffNeighbor[4] = {1, 63, 64, 65};
  24.  
  25.             int j;
  26.             for (j = 0; j < 4; ++j)
  27.             {
  28.                 if(world[(i + diffNeighbor[j]) % 2048] & (1 << 5))
  29.                 {
  30.                     ++world[i];
  31.                 }
  32.                 if(world[(i - diffNeighbor[j]) % 2048] & (1 << 5))
  33.                 {
  34.                     ++world[i];
  35.                 }
  36.  
  37.                 if(j==3)
  38.                 {
  39.                     // Apply "game of life" rule.
  40.                     world[i] |= ((world[i] ^ 34) && (world[i] ^ 35)) ? ( (world[i]^3) ? 0 : (1<<4)) : (1<<4);
  41.                 }
  42.             }
  43.         }
  44.        
  45.         for (i = 1; i < 2048; ++i)
  46.         {
  47.             world[i] = ( world[i] & (1 << 4) ) << 1; // set new call state from old state
  48.             putchar(world[i] ? 'X':' ');
  49.  
  50.             if((i-1)%64==0) //if(!(63^i % 64))
  51.             {
  52.                 putchar('\n');
  53.             }
  54.         }
  55.        
  56.         usleep(102400);
  57.     }
  58. }
Add Comment
Please, Sign In to add comment