Task
Given a list of integers L and another integer s, the goal is to compute the column-wise sums of all s-length (potentially overlapping) slices of L, while pertaining their positions relative to L (see below).
Definitions
The s-length (overlapping) slices of the list L are all the contiguous subsequences (without wrapping) of L that are of length s.
In order to pertain the positions of the slices s relative to L, you can imagine building a "ladder", where each slice si has an offset of i positions from the beginning.
Specs
- s is an integer higher than 1 and strictly smaller than the length of L.
- L will always contain at least 3 elements.
- You can compete in any programming language and can take input and provide output through any standard method, while taking note that these loopholes are forbidden by default. This is code-golf, so the shortest submission (in bytes) for every language wins.
Examples and Test Cases
Here is a worked example:
[1, 2, 3, 4, 5, 6, 7, 8, 9], 3
[1, 2, 3]
[2, 3, 4]
[3, 4, 5]
[4, 5, 6]
[5, 6, 7]
[6, 7, 8]
[7, 8, 9]
-------------------------------- (+) | column-wise summation
[1, 4, 9, 12, 15, 18, 21, 16, 9]
And some more test cases:
[1, 3, 12, 100, 23], 4 -> [1, 6, 24, 200, 23]
[3, -6, -9, 19, 2, 0], 2 -> [3, -12, -18, 38, 4, 0]
[5, 6, 7, 8, 2, -4, 7], 3 -> [5, 12, 21, 24, 6, -8, 7]
[1, 2, 3, 4, 5, 6, 7, 8, 9], 3 -> [1, 4, 9, 12, 15, 18, 21, 16, 9]
[1, 1, 1, 1, 1, 1, 1], 6 -> [1, 2, 2, 2, 2, 2, 1]
[1, 2, 3, 4, 5, 6, 7, 8, 9], 6 -> [1, 4, 9, 16, 20, 24, 21, 16, 9]
s
is larger thanL/2
. Maybe add some more test cases where that is the case[1, 1, 1, 1, 1, 1, 1], 6 ->
[1, 2, 2, 2, 2, 2, 1]` or[1, 2, 3, 4, 5, 6, 7, 8, 9], 6 -> [1, 4, 9, 16, 20, 24, 21, 16, 9]
? \$\endgroup\$