I have this math sequence that produces list of values:
(n-1)*1 , (n-2)*2 , (n-3)*3 , ... , (1)*(n-1)
So for n = 5 it would produce this list of values:
1,1,1,1, 2,2,2, 3,3, 4
Median of this list is 2, right? So how to calculate median for whatever n from natural numbers?
I am searching for some formula. I have already found out that number of those values is:
((n^2) - n) / 2
You want to count $k=\frac 14(n^2-n)$ positions from one end of the list. It is easier to count back from the end because the end of each group of the same number comes at the triangular numbers: $1,3,6,10\ldots$. Given $k$ the triangular number above it is $\lceil \frac 12(-1+\sqrt{1+8k})\rceil$ so the median will be $n-\lceil \frac 12(-1+\sqrt{1+2(n^2-n)})\rceil$
The place this fails is when $n+1$ is such that $\frac 12n(n-1)$, which is a triangular number, is also twice a triangular number. One example is $n=21$ where you series has $\frac 12n(n-1)=210$ terms. The first $105$ terms (which is $\frac 12 \cdot 14 \cdot 15$) go from $20$ through the last $7$ so many would say the median is $6.5$. You can detect this because the square root comes out integral. In those cases you should subtract $\frac 12$