Index sum and strip my matrix
MATL, 36 34 bytes
tnq?`t&+stn:*sytn2/)+ 7M(6Lt3$)tnq
Input is a 2D array with ;
as row separator
Try it online! Or verify all test cases.
Explanation
tnq % Take input. Duplicate, get number of elements, subtract 1
? % If greater than 0
` % Do...while
t % Duplicate
&+ % Sum matrix with its transpose
s % Sum each column. Gives a row vector
tn: % Vector [1 2 ...] with the same size
* % Multiply element-wise
s % Sum of vector. This will be added to center entry of the matrix
y % Duplicate matrix
tn2/ % Duplicate, get half its number of elements. Gives non-integer value
) % Get center entry of the matrix, using linear index with implicit rounding
+ % Add center entry to sum of previous vector
7M % Push index of center entry again
( % Assgined new value to center of the matrix
6Lt % Array [2 j1-1], twice. This will be used to remove shell
3$) % Apply row and col indices to remove outer shell of the matrix
tnq % Duplicate, number of elements, subtract 1. Falsy if matrix has 1 entry
% End do...while implicitly. The loop is exited when matrix has 1 entry
% End if implicitly
% Display stack implicitly
Python 2.7, 229 bytes
This is my first attempt at something like this, so hopefully I followed all the rules with this submission. This is just a function which takes in a list of lists as its parameter. I feel like the sums and list comprehension could probably be shortened a little bit, but it was too hard for me. :D
def r(M):
t=len(M)
if t==1:return M[0][0]
M[t/2][t/2]+=sum(a*b for k in [[l[x] for l in M]for x in range(0,t)]for a,b in enumerate(k,1))+sum([i*j for l in M for i,j in enumerate(l,1)])
return r([p[+1:-1]for p in M[1:-1]])
Thx to Easterly Irk for helping me shave off a few bytes.
C#, 257 bytes
here is a non esolang answer
void f(int[][]p){while(p.Length>1){int a=p.Length;int r=0;for(int i=0;i<a;i++)for(int j=0;j<a;j++)r+=(i+j+2)*p[i][j];p[a/2][a/2]+=r;p=p.Where((i,n)=>n>0&&n<p.Length-1).Select(k=>k.Where((i,n)=>n>0&&n<p.Length-1).ToArray()).ToArray();}Console.Write(p[0][0]);
ungolfed:
void f(int[][]p)
{
while (p.Length>1)
{
int a=p.Length;
int r=0; //integer for number to add to middle
for (int i = 0; i < a; i++)
for (int j = 0; j < a; j++)
r +=(i+j+2)*p[i][j]; //add each element to counter according to their 1 based index
p[a / 2][a / 2] += r; //add counter to middle
p = p.Where((i, n) => n > 0 && n < p.Length - 1).Select(k => k.Where((i, n) => n > 0 && n < p.Length - 1).ToArray()).ToArray(); //strip outer shell from array
}
Console.Write(p[0][0]); //print last and only value in array
}