General Summation Formula for $\{0,\,1,\,2,\,3,\dotsc x \dotsc,3,\,2,\,1,\,0\}$

64 Views Asked by At

I have a series of $n$ elements which I index with $i$: for example $1\leq i\leq 10$ for $n=10$.

I need a summation formula to represent this:

  • When $i = 1$, add $0$
  • When $i = 2$, add $1$
  • When $i = 3$, add $2$
  • When $i = 4$, add $3$
  • When $i = 5$, add $4$
  • When $i = 6$, add $4$
  • When $i = 7$, add $3$
  • When $i = 8$, add $2$
  • When $i = 9$, add $1$
  • When $i = 10$, add $0$

I tried to do a general formula to get the answer and got to $$(n/2 - \operatorname{ABS}(i - (n/2)))$$ which works when $i$ is larger than $n/2$ but fails when $i$ is smaller than $n/2$.

1

There are 1 best solutions below

0
On BEST ANSWER

$$\frac{n-1-|2i-n-1|}2\qquad (1\leqslant i\leqslant n)$$