Function which creates the sequence 1, 2, 3, 1, 2, 3, ...
Solution 1:
You figured out already that $\,x \bmod n\,$ gives the periodic sequence $\,(1, 2, \ldots, n-1, \color{red}{0}, 1, \ldots)\,$ then the rest is just "shifting" it to fit the desired start/end values. To match $\,(1, 2, \ldots, \color{red}{n}, 1, \ldots)\,$ for example, you need to shift $\,x \bmod n\,$ up by $\color{blue}{1}$, and $\,x\,$ down by $\color{green}{1}$ to compensate for it. So in the end you'd be getting $\,\color{blue}{1} + (x-\color{green}{1}) \bmod n\,$, and of course $\,(x-1) \bmod n = (x+n-1) \bmod n\,$.
Solution 2:
The $k$:th number will be: $$[1,0,0]{\bf C}^k[1,2,3]^T$$
where ${\bf C}= \left[\begin{array}{ccc}0&1&0\\0&0&1\\1&0&0\end{array}\right]$
Now you can exchange the vector to the right for any ordered set of numbers you want to $\bf C$ycle through.
(It is actually a representation matrix for a generator of the cyclic group $C_3$ if you want to dig into some theory).
Now to make this a function of $k$, (which is actually what is asked), maybe you prefer the notation
$$k\overset{f(k)}{\longrightarrow} [1,0,0]{\bf C}^k[1,2,3]^T$$ or maybe
$$f(k)= [1,0,0]{\bf C}^k[1,2,3]^T$$
Solution 3:
As an alternative, here is a purely trigonometric function which generates the required sequence:
$$f(x)=\frac{\sqrt{3}\sin(\frac 23\pi(x-2))}{\cos(\frac 23\pi(x-2))+2}+2$$
Here we have $f(1)=1$, $f(2)=2$, $f(3)=3$, $f(4)=1$, and so on.