I was wondering how to map the set $\mathbb{Z}^+$ to the sequence $1, 2, 3, 1, 2, 3, \ldots$. I thought it would be easy, but I was only able to obtain an answer through trial and error.
For a function $f \colon \mathbb{Z}^+ \rightarrow \mathbb{Z}$, we have that
$f(x) = x \bmod 3$ gives the numbers $1, 2, 0, 1, 2, 0, \ldots$
$f(x) = (x \bmod 3) + 1$ gives the numbers $2, 3, 1, 2, 3, 1, \ldots$
After a bit of experimenting, I finally found that
$f(x) = ((x + 2) \bmod 3) + 1$ gives the numbers $1, 2, 3, 1, 2, 3, \ldots$
More generally, if I want to map the set $\mathbb{Z}^+$ to the sequence $\{1, 2, \ldots, n, 1, 2, \ldots, n, \ldots\}$, I need to use the function
$$f(x) = ((x + n - 1) \bmod n) + 1$$
I was only able to come to this result by trial and error. I was not able to find a solution to this relatively simple question online (although perhaps my search terms were off).
How would one come to this result in a more systematic way?
$f(x)=\left\lfloor 10^x\cdot {123\over999}\right\rfloor\mod 10$.
More generally, with $b>n>1$, $$f(x)=\left\lfloor b^x\cdot {(123\ldots n)_b\over b^n-1}\right\rfloor\mod b. $$