Index sum and strip my matrix
Given a matrix/2d array in your preferable language
Input:
- The matrix will always have an odd length
- The matrix will always be perfectly square
- The matrix values can be any integer in your language (positive or negative)
Example:
1 2 3 4 5 6 7 2 3 4 5 6 7 8 3 4 50 6 7 8 9 4 5 6 100 8 9 10 5 6 7 8 -9 10 11 6 7 8 9 10 11 12 7 8 900 10 11 12 0 Definitions:
- The "central number" is defined as the number that has the same amount of numbers to the left,right,up and down
In this case its middlemost 100
- The "outer shell" is the collection of numbers which their x and y index is or 0 or the matrix size
1 2 3 4 5 6 7 2 8 3 9 4 10 5 11 6 12 7 8 900 10 11 12 0 Your task:
Add to the central number the sum of each row and column after multiplying the values in each by their 1-based index
A single row for example
4 5 6 7 8 for each number
number * index + number * index..... 4*1 + 5*2 + 6*3 + 7*4 + 8*5 => 100 example:
2 -3 -9 4 7 1 5 => 61 -2 0 -2 -7 -7 -7 -4 => -141 6 -3 -2 -2 -3 2 1 => -10 8 -8 4 1 -8 2 0 => -20 -5 6 7 -1 8 4 8 => 144 1 5 7 8 7 -9 -5 => 10 7 7 -2 2 -7 -8 0 => -60 | 78 65 60 45 -15 -89 10 => 154 | => -16 - For all rows and columns you combine these values..
- Now you sum these too => 154-16 = 138
- You add that number to the "central number" and remove the "outer shell" of the matrix
0 -2 -7 -7 -7 => -88 -3 -2 -2 -3 2 => -15 -8 4 1+138 -8 2 => 395 6 7 -1 8 4 => 69 5 7 8 7 -9 => 26 19 69 442 30 -26 do this untill you end up with a single number
-2 -2 -3 => -15 4 1060 -8 => 2100 7 -1 8 => 29 27 2115 5 - Add 2114+2147 to 1060
- Remove the "outer shell" and get 5321
- Now we have a single number left
this is the output!
test cases:
-6 -6 -7 -1 8 -4 -6 7 -3 -6 6 2 6 7 -2 5 1 -2 6 -4 -2 3 -1 -4 0 -2 -7 0 1 4 -4 8 -8 -6 -5 0 2 -365 8 3 5 6 6 -7 5 6 2 4 -2 -1 8 3 2 1 -5 3 8 2 -3 3 -1 0 7 -6 7 -5 0 -8 -4 -9 -4 2 -8 8 -9 -3 5 7 8 5 8 -1 4 5 1 -4 8 17611 -9 -7 2 1 1 -2 3 -7 -3 6 7 1 0 -7 -8 -9 -2 7 -2 5 4 7 -7 8 -9 8 -4 4 -1 0 1 5 -3 7 1 -2 -9 4 8 4 8 1 -1 0 7 4 6 -9 3 -9 3 -9 -6 -8 -4 -8 -9 2 1 1 -8 8 2 6 -4 -8 -5 1 1 2 -9 3 7 2 5 -6 -1 2 -8 -5 -7 -4 -9 -2 5 0 2 -4 2 0 -2 -3 -6 -3 2 -9 8 1 -5 5 0 -4 -1 -9 -9 -9 -8 0 -5 -7 1 -2 1 -4 -1 5 7 -6 -9 4 -2 8 7 -9 -5 3 -1 1 8 4 -6 6 -3 -4 3 5 6 8 -2 5 -1 -7 -9 -1 7 -9 4 6 7 6 -8 5 1 0 -3 0 -3 -2 5 -4 0 0 0 -1 7 4 -9 -4 2 -28473770