/* Copyright (C) 2014 by Alexandru Cojocaru */

/* This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */


/* gcc -Wall -std=c99 183.c -o /tmp/183 && /tmp/183 */

#include <stdio.h>
#include <stdbool.h>

static bool
fill_p (int y, int x, int n)
{
	int leny;

	leny = n+2;
	for (int cornery = 1; cornery <= n/2 + 1; cornery += 2) {
		int cornerx = cornery-1;
		int lenx = leny-1;
		if ((x == cornerx && y >= cornery && y < cornery + leny) ||
		    (y == cornery && x >= cornerx && x < cornerx + lenx))
			return 1;

		leny -= 4;
	}

	leny = n;
	for (int cornery = n; cornery > n/2 + 1; cornery -= 2) {
		int cornerx = cornery;
		int lenx = leny-1;
		if ((x == cornerx && y <= cornery && y > cornery - leny) ||
		    (y == cornery && x <= cornerx && x > cornerx - lenx))
			return 1;

		leny -= 4;
	}

	return 0;
}


static void
drawsqspiral (int n)
{
	for (int y = 1; y <= n; ++y) {
		for (int x = 1; x <= n; ++x) {
			if (fill_p (y, x, n))
				printf ("@");
			else
				printf (" ");
		}

		printf ("\n");
	}
}

int
main ()
{
	int n = 16;
	drawsqspiral (n);

	return 0;
}