public static void main(String[] args) {
		int size = 1001;

		int[][] spiral = new int[size][size];

		int i = 1;
		int middleX = size / 2;
		int middleY = middleX;

		int x = middleX;
		int y = middleY;

		spiral[x][y] = i++;

		int border = 1;

		while (border <= middleX) {
			// Einen nach unten
			spiral[x][++y] = i++;

			// Nach links
			while (x > middleX - border) {
				spiral[--x][y] = i++;
			}

			// Nach oben
			while (y > middleY - border) {
				spiral[x][--y] = i++;
			}

			// Nach rechts
			while (x < middleX + border) {
				spiral[++x][y] = i++;
			}

			// Nach unten
			while (y < middleY + border) {
				spiral[x][++y] = i++;
			}

			border++;
		}

		System.out.println("Result = " + buildSum(spiral));
	}