Print an ascii spiral in O(log n) memory You may write a program or function that receives an odd, positive integer n, where n &gt;= 3, as either a function argument, command line arguments, or on STDIN (or equivalent for your system), and prints to STDOUT (or system equivalent) an ASCII spiral that spins inward clockwise where the top edge is exactly n characters long. The first right edge should be n+1 characters long, obviously. For instance,

Input:

11

Output:

***********
          *
********* *
*       * *
* ***** * *
* *   * * *
* * * * * *
* * *** * *
* *     * *
* ******* *
*         *
***********


The catches:


Your program must use no more than O(log n) memory.
Your program may only print the characters * (ASCII 42),  (ASCII 32), &lt;CR&gt; (ASCII 13) and &lt;LF&gt; (ASCII 10).
Your program must print the string, not return it from the function.
The Big-O restriction is only on memory, there are no restrictions on runtime.
A trailing newline is optional.
If your language does not support large integer types, you do not have to support higher than what it does support, but you may not use this as a trick to say "oh, well, I don't have to support above X so I can just make a huge array the maximum size every time"


Standard loopholes are banned, as usual.
C, 125 121 bytes
Golfed version This has no variable k. The variable k is used in the ungolfed version just to aid readability. Also for loop conditionals are rearranged and one set of unnecessary {} removed. Another set of {} can be removed by migrating puts(&quot;&quot;) inside the brackets of the j loop in the initialization position, but this would mean a newline at the beginning of the output, so I haven't done it.
f(n){int i,j;n/=2;for(i=-n-2;i++-n-1;){if(i){for(j=-n-1;j++-n;)putchar(32+10*(n+(j*j&lt;i*i?i:j+(i!=j|i&gt;0))&amp;1));puts(&quot;&quot;);}}}

Prints an n wide by n+1 high spiral like the example.
Explanation
Basically I halve the value of n (rounding down) and run two loops: an outer one i from -n/2-1 to n/2+1 to print the rows (i=0 is suppressed so we get n+1 rows) and an inner one j from (-n/2 to n/2 to print the characters.) We use expression &amp; 1 to print stripes, and the condition j*j&lt;i*i to decide whether to print vertical or horizontal stripes (vertical at the sides where absolute magnitude of i is larger, and horizontal at the top and bottom.) An adjustment +n is required to help with the correct termination depending on whether n/2 is odd or even.
k is normally 1, and provides an adjustment for the fact that the absolute values of i range from 1 to n/2+1 while the absolute values of j range from 0 to n/2. If k was always 1 we would get concentric rectangles, but it is inverted to 0 when i==j&amp;i&lt;=0 so that a diagonal row of cells is inverted, producing the spiral.
ungolfed in test program
f(n){
  int i,j,k;
  n/=2;
  for(i=-n-1;i&lt;=n+1;i++){
    if(i){
       for(j=-n;j&lt;=n;j++){
           k=i!=j|i&gt;0;
           putchar(32+10*(n+(j*j&lt;i*i?i:k+j)&amp;1));
         }
       puts(&quot;&quot;);
     }
  }
} 

int m;
main(){
  scanf(&quot;%d&quot;,&amp;m);
  f(m);
}

Output
11
***********
          *
********* *
*       * *
* ***** * *
* *   * * *
* * * * * *
* * *** * *
* *     * *
* ******* *
*         *
***********

9
*********
        *
******* *
*     * *
* *** * *
* * * * *
* *   * *
* ***** *
*       *
*********

3
***
  *
* *
***

1
*
*