I need a function that, starting at $0$ or $1$, gives the sequence $$1,2,2,3,3,3,4,4,4,4,5,5,5,5,5...$$ In other words, has $n$ copies of $n$. What is the simplest such function, hopefully non-piecewise?
2026-04-17 17:52:25.1776448345
On
Function generating $n$ copies of $n$
66 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
3
There are 3 best solutions below
0
On
The end of the run of $n$ is $T_n$, the $n^{th}$ triangular number. $T_n=\frac 12n(n+1)$ You want to invert this relationship. Given $k$, the position in the list, you want to find the $n$ that has $T_{n-1} \lt k \le T_n$. That is $n=\lceil \frac 12(1+\sqrt{8k+1})\rceil$
$$f(n) = \left\lfloor \frac{1}{2} + \sqrt{2n} \right\rfloor$$
Or, if you let $[x]$ be the nearest integer to $x$ it simplifies to $f(n) = [\sqrt{2n}]$.