Sum a series of series where each value increments by one

2.7k Views Asked by At

Can anyone suggest an elegant way to sum a series of numbers like this:

    (1, 2, 3, 4)
    (2, 3, 4, 5)
    (3, 4, 5, 6)
    (4, 5, 6, 7)

That is for $n$ sets of $d$ numbers, what is the total of all numbers?

For example in the series above, the total should be 64

2

There are 2 best solutions below

3
On

For n sets of d numbers, there must be an average number. If all of the rows increment by 1 then you could just take the average of the two corners, top left and bottom right to get the average for all spots.

Example:

Average of $1$ and $7$ (rows+columns-1) is $4$ (which is always $(n+d-1+1)/2$)

$4$ (average) times $4$ (rows) times $4$(columns) is $64$

So the total is $\frac{n+d}{2}*n*d$ if it always increments by one for ever row and column and it starts at one at the top left corner.

13
On

If you pair the $n$th number in the array, counting from the top left, with the corresponding number in the array counting from the bottom right, the total is always constant (in this example, we have $1+7=2+6=3+5=4+4=2+6= \cdots = 8$). In an array with $n$ rows of $d$ numbers the number of such pairs will be $nd/2$.