I feel like this should be obvious for me, but I am not understanding this one. Given: 1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,..., I need to find a function for this. Thank you.
Asked
Active
Viewed 97 times
2 Answers
7
The On-Line Encyclopedia of Integer Sequences gives several formulas, including $$ a_n=\left\lfloor\frac{1}{2}+\sqrt{2n}\right\rfloor $$
The main point is that the sequence changes values at positions $1,2,4,7,11,\dots$, which is the sequence of triangular numbers $0,1,3,6,10,\dots$ shifted $1$ and these triangular numbers are given by $\frac{k(k-1)}{2}$. Hence the sequence of positions where the original sequence changes values is given by $j_k=\frac{k(k-1)}{2}+1$, $k=1,2,\dots$.
So the original sequence is given by $a_n=k$ if $j_k \le n < j_{k+1}$.
lhf
- 216,483
0
f(x) = if (x mod f(x - 1) == 0)
then
x mod f(x - 2) + 1
else
x mod f(x - 1)
Only I don't know how to put if in to a math function.
Ilya Gazman
- 1,440
-
@DennisGulko I think you did not understand my % sign. I edit the question and changed it to mod – Ilya Gazman Oct 16 '13 at 10:57