I recently saw the following puzzle somewhere:
Find a continuous, surjective function $f:\mathbb R\mapsto\mathbb R$ that takes on each of its values exactly three times.
Or, more technically stated,
Find a continuous, surjective function $f:\mathbb R\mapsto\mathbb R$, such that for all $y\in\mathbb R$, there exist exactly three real solutions $x$ to the equation $f(x)=y$.
My solution to this puzzle was the function $$f(x)=\sin^2 \frac{3\pi(x-\lfloor x\rfloor)}{2}+\lfloor x\rfloor$$ Since then, I've thought of a few variations on this puzzle, none of which I have been able to solve:
- Can a function $g:\mathbb R\mapsto \mathbb R^2$ satisfy these requirements? What about a function $h:\mathbb R^2\mapsto \mathbb R$?
- What function $f$ satisfies the original puzzle, and is also $C^\infty$?



Starting from the following idea:
$$g(x)=\sin x + \frac{2}{3\pi}x$$
g(x) plot
we can adjust the constant for x in such way that
$$f(x)=\sin x + Kx$$
fullfills the given condition.
The value of K can be easily found imposing that:
$$\begin{cases}(\sin x)'=\cos x=-K\\ Kx=-\sin x\end{cases}$$
$$\implies tanx=x \implies x\approx4.49340945790906 \quad K=-\cos x \approx 0.21723362821123...$$
f(x) plot