Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Okay this is a solution that</strong> </p> <ul> <li>uses just one extra long value for working storage.</li> <li>uses no recursion.</li> <li>one pass of only N, not even N*N.</li> <li>will work for other values of N but will need new #defines.</li> </ul> <blockquote> <pre><code>#include &lt;stdio.h&gt; #define BIT30 (1&lt;&lt;24) #define COLMASK 0x108421L #define ROWMASK 0x1fL </code></pre> </blockquote> <pre><code>unsigned long long STARTGRID = ((0x10 | 0x0 | 0x4 | 0x2 | 0x0) &lt;&lt; 20) | ((0x00 | 0x8 | 0x4 | 0x2 | 0x0) &lt;&lt; 15) | ((0x10 | 0x8 | 0x4 | 0x2 | 0x1) &lt;&lt; 10) | ((0x10 | 0x0 | 0x4 | 0x2 | 0x1) &lt;&lt; 5) | ((0x10 | 0x8 | 0x4 | 0x2 | 0x1) &lt;&lt; 0); void dumpGrid (char* comment, unsigned long long theGrid) { char buffer[1000]; buffer[0]='\0'; printf ("\n\n%s\n",comment); for (int j=1;j&lt;31; j++) { if (j%5!=1) printf( "%s%s", ((theGrid &amp; BIT30)==BIT30)? "1" : "0",(((j%5)==0)?"\n" : ",") ); theGrid = theGrid &lt;&lt; 1; } } int main (int argc, const char * argv[]) { unsigned long long rowgrid = STARTGRID; unsigned long long colGrid = rowgrid; unsigned long long rowmask = ROWMASK; unsigned long long colmask = COLMASK; dumpGrid("Initial Grid", rowgrid); for (int i=0; i&lt;5; i++) { if ((rowgrid &amp; rowmask)== rowmask) rowgrid |= rowmask; else rowgrid &amp;= ~rowmask; if ((colGrid &amp; colmask) == colmask) colmask |= colmask; else colGrid &amp;= ~colmask; rowmask &lt;&lt;= 5; colmask &lt;&lt;= 1; } colGrid &amp;= rowgrid; dumpGrid("RESULT Grid", colGrid); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload