I have a 2D array which is a square matrix 4x4.
First I generated the permutation of '1234' S = "1234124313241423........."(in fact it should be '0123', Let's ignore that for now.) if it's 5x5 it would be '12345'
I would like to iterate through a 2D array and sum every 4 elements with the following fashion:
The row-index follow the fixed pattern 1234,1234,1234.
The column-index is pulled from the permuted string.
input 2D Array which is a 4x4 matrix:
{9,2,7,8},
{6,4,3,7},
{5,8,1,8},
{7,6,9,4}
the 2D array can be represented as a[i][j], i for rows and j for columns, columns are pulled from S = "1234124313241423" chop every 4 digits from the string.
index index
Read from left to right
a11+a22+a33+a44 => 9+4+1+4=18 rows: 1 2 3 4 columns: 1 2 3 4
a11+a22+a34+a43 => 9+4+8+9=30 rows: 1 2 3 4 columns: 1 2 4 3
a11+a23+a32+a44 => 9+3+8+4=24 rows: 1 2 3 4 columns: 1 3 2 4
a11+a24+a32+a43 ...........
.
.
.
output:18,30,24,....
It seems like a standard nested loop won't do the job.