On Monday, 19 March 2018 at 14:41:27 UTC, rumbu wrote:
Sorry, but I fail to understand your requirements. Do you have a practical example?

Doing this without writing a loop or using arrays for memoizing half-finished calculations:

public static int Foo(int[] input)
{   int result = 10;
    for (int i = input.Length / 4; i >= 0; i -= 4)
    {   int sum = 0;
for (int j = i; j < i +4 && j < input.Length; j++) sum += input[j];
        sum *= i;
        result = (result + sum) / 2;
    }
    return result;
}

To be honest, this is as artificial as it looks. When I look again at my code, it seems that my main problem was that I have not made a habit to input.Zip(Enumerable.Range(0, inputLength), Tuple.Create) or similar when I need indexing in C# :).

I'm still interested in the answer, though.

Reply via email to