It is probably easiest to think of this as the sum of two separate series, one for which i%3 = 1 and the other for i%3=2 . Alternatively, you can represent it as the sum for all i values ββminus the sum for i%3=0 . For argumentation, we consider the first half of the last approach: we summarize all the width values.
In this case, width will start from some initial value, and each iteration its value will be reduced by 1. In the last iteration, its value will be reduced by (end-start) . Perhaps the easiest way to think of it is as a triangle. Just to make everything simple, we will use small numbers - we will start with width = 5, start = 1 and end = 5. Perhaps the easiest way is to draw a diagram:
Width Values:
* ** *** **** *****
What we are really looking for is the area of ββthis triangle - a fairly well-known formula from elementary geometry - 1 / 2ab, where a and b are the lengths of two sides (in this case, determined by the initial value of width and end-start ). This suggests that it is indeed a triangle, though, i.e. That it decreases to 0. In fact, there is a good chance that we are dealing with a truncated triangle, but the formula for this is also well known (1 / 2a 1 b + 1 / 2a 2 b, where a are the heights of the right and left sides , and b is the width.
source share