Main Question
Setup
Given nonnegative integer parameters $x$ and $y$, we define a sequence $\langle a_n:n=0,1,\ldots \rangle$ which alternates between a single $x$ and runs of consecutive entries equal to $y$, where the length of each run is given by the corresponding entry in the sequence.
For example, if $x=2$ and $y=3$, we have the sequence: $2,3,3,2,3,3,3,2,3,3,3,2,3,3,2,3,3,3,2,3,3,3,2,3,3,3,\ldots$ where the first runs of $3$s have lengths $2,3,3,2$, respectively, because those are the first entries in the sequence. If $x=3$ and $y=0$, we have a sequence: $3, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 3, 3, 3, 3,\ldots$
Question
The cases of $x=0$ or $x=y$ both lead to $a_n=x$ for all $n$. Less trivially, in the special case where $y=x+1$, $a_n$ is given by a tidy non-recursive formula involving floor and a square root, such as $a_n=\left\lfloor(n+1)\cdot\dfrac{x+2+\sqrt{x^2+4x}}{2}\right\rfloor-\left\lfloor (n)\cdot\dfrac{x+2+\sqrt{x^2+4x}}{2}\right\rfloor-1\tag{1}\text{.}$
Is there a similar closed form for the general case?
Context
I discovered this collection of sequences in What is the pattern in this infinite sequence? [closed], where BOBOBOY was asking for Python code to generate the sequences. I tried briefly to find a tidy formula on my own, and noted that the indices where $a_i=x$ are $0,1+a_0,2+a_0+a_1,3+a_0+a_1+a_2,\ldots$.
This means we could define the sequence by $$a_{n}=\begin{cases} x & \text{if }n=0\\ \begin{cases} x & \text{if }k=n\\ y & \text{if }k>n \end{cases}\text{ where }k\text{ is least so }k+1+\sum_{i=0}^{k}a_{i}\ge n & \text{if }n>0 \end{cases}\tag{2}\text{.}$$
It turns out that the case $x=2$ and $y=3$ is A007538 in the OEIS because the question of identifying the indices where $a_n=2$ (essentially the same as finding a formula for $a_n$) was question A-6 on the 1993 Putnam Exam. You can see one phrasing of the question and a solution at Kalva (questions, solution) and another at the MAA article for that Putnam.
The solution to that Putnam problem readily generalizes from $x=2,y=3$ to all $y=x+1$ (though $x=0$ may need to be checked separately): the indices where $a_n=x$ are those of the form $\left\lfloor (m)\cdot\dfrac{x+2+\sqrt{x^2+4x}}{2}\right\rfloor$, which leads quickly to the formula (1) above. (The formula simplifies a bit if $x$ is known to be even or known to be odd.)
It seems a new approach/sort of formula is needed for the general case, but I'm not sure what form to guess. I doubt there is a very similar formula with a different (usually) irrational number depending on both $x$ and $y$, because the asymptotic heuristics featured in the MAA article seem to lead one to the guess of $\dfrac{y+1+\sqrt{(y-1)^2+4x}}{2}$, which doesn't seem to work unless $y=x+1$.
(I'm open to other tags, but chose continued-fractions simply because they came up in the comments of the related A188070, and quadratic irrationals have periodic continued fractions.)