Background
Imagine, you have a big array A, which is mostly zeroes, but contains a short subarray B which has only strictly positive entries. For instance:
| A |
[0 0 0 0 1 2 3 0]
| B |
Now say, we split the array A into consecutive subarrays of length d (with a shorter final array, if the d doesn't divide the length of A). For d = 3:
[0 0 0 0 1 2 3 0]
| |
[0 0 0] [0 1 2] [3 0]
And now sum up each of those arrays:
[0 3 3]
And discard zero sums:
[3 3]
The Challenge
You're to write a function which prints that final array of sums in any convenient array format, given the following 5 parameters (or any subset thereof, if you don't need all of them):
- The small array
B. - The size of the small array
B(3in the above example). - The size of the big array
A(8in the above example). - The index where the small array begins (
4in the above example). - The length
dof the subarrays (3in the above example).
The Rules
- You are not allowed to construct the big array
Aexplicitly! - You are not allowed to construct any of the subarrays of length
dexplicitly! - That means you have to get the computation directly from the
Band the other parameters at your disposal!
Fewest characters wins!
size_bigarrayorsize_smallarrayat all. \$\endgroup\$small_array? In your example, that would only be[0,1,2], 3,0]. Or none at all? \$\endgroup\$