What a brain-bender. I can see a pattern here, I just can't quite paramaterize it any better just yet.
Looking at your example, I noted down the number of asterisks and spaces on each line. This gave me the following table:
* *** * ***
** ** ** **
*** * *** *
1, 5, 3, 7, 1, 5, 3
2, 5, 2, 6, 2, 5, 2
3, 5, 1, 5, 3, 5, 1
You can clearly see a relationship in the odd-numbered columns to the max number of rows, N.
You can also see that the even numbered columns have their own patterns -
n+1+2, 2*(n+1)-row, n+1+2 N+2, 2*(N+1)-row, N+2
I smashed together a version using for loops, then re-read your question. So I converted them to while loops. Clearly, I'm using more than 1 line of code. But, in doing so - I noticed that there was a re-occurant pattern along each row. 1,5,3 in the first row is repeated, as is 2,5,2 in the second. What a total brain buster!!
Here's some ode to consider. Perhaps you can identify a pattern I've just not quite come to grips with yet. A patter that would eliminate much of the repetition I've exhibited and in doing so, produce code that is (almost/actually) reasonable as a single line of code.
I tested with N ranging up to about 25 and was rewarded with the same pattern, albeit scaled ever larger. Note that for the ease/brevity of the terminating condition of each while loop, N holds a number 1 larger than the number of rows you'd actually like to print.
int main()
{
int row, sp, st;
int n = 4;
row=1; while (row < n)
{
st=0; while(st++ < row) printf("*");
sp=0; while(sp++ < n+1) printf(" ");
st=0; while(st++ < n-row) printf("*");
sp=0; while(sp++ < 2*n-row) printf(" ");
st=0; while(st++ < row) printf("*");
sp=0; while(sp++ < n+1) printf(" ");
st=0; while(st++ < n-row) printf("*");
printf("\n");
row++;
}
return 0;
}
Here's a sample of (my)n = 10
* ********* * *********
** ******** ** ********
*** ******* *** *******
**** ****** **** ******
***** ***** ***** *****
****** **** ****** ****
******* *** ******* ***
******** ** ******** **
********* * ********* *
My head hurts!