I am working with a 3 by 5 matrix, filled with numbers from 1, presented as follows:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
The task is to print the values in a half-spiral order, starting from the bottom left vertically: 11 6 1 5 10 15 12 7 2 4 9 14 13 8 3.
After numerous attempts, I realize my current solution is too complicated. Even after 2 days of trying, I still can't figure out how to alternate between printing the opposing side columns.
var c = 0;
var i, j, k, l;
do {
if (c == 0) {
c++;
for (j = 0; j < farm[0].length; j++) {
for (i = farm.length - 1; i >= 0; i--)
document.write(farm[i][j] + " ");
break;
}
} else {
c--;
for (l = farm[0].length - 1; l >= 0 ; l++) {
for (k = 0; k < farm.length; k++)
document.write(farm[k][l] + " ");
break;
}
}
} while (j < l);