Does there exist any continuous function $f:\mathbb{R} \to \mathbb{R}$ such that $f(\mathbb{R}\setminus \mathbb{Q}) = \mathbb{R}$? My attempt to the problem is first I intend to make a perfect nowhere dense set of irrational numbers of measure $0$ like cantor set(and that I guess we could do)..now make such type of function like cantor function on that closed interval end with irrational endpoints from which we initially start work to make such cantor set types set consisting with irrationals only.
 A: There is a continuous map of the unit interval onto unit square (so called Peano curve)
Compose it with the projection onto $x$ -axis.
One gets a continuous map from the unit interval onto unit interval such that inverse image of each point is uncountable. Hence, for each rational there must be an irrational mapped into it.
A: Let $g$ be defined on $[0,1]$ with $$g(0)=0, g(1/\sqrt3)=1, g(2/3)=0,g(1)=1,$$ and the function is linear between these values. Then define $$f(x)=g(x-\lfloor x\rfloor )+\lfloor x\rfloor.$$
You can replace $1/\sqrt3,2/3$ with any pair $0<a<b<1$ with exactly one of $a,b$ rational.
Then for any real $r,$ $f^{-1}(r)$ has at least three elements (more if $r$ is an integer) and at least one of these elements is irrational.
Assume $r=n+y$ for $n\in\mathbb Z$ and $0\leq y<1.$
If $y=0,$ $f(n-1+1/\sqrt3)=r.$
If $r$ is irrational, then $f(x)=r$ for $x=n+2/3+y/3,$ which is irrational.
If $r$ is rational and not an integer, then $f(x)=r$ for $x=n+y/\sqrt3,$ which is irrational.
A: Here is an idea:
Consider the following maps from $\{0,1\}^{\mathbb{N}}$ to $[0,1]$
$$\phi((a_n)) = \sum_{n\ge 1} \frac{a_n}{2^n} \\
\psi((a_n)) = \sum_{n\ge 1} \frac{1+a_n}{3^{n^2}}$$
Both $\phi$, $\psi$ are continuous, and moreover, $\phi$ is surjective and $\psi $ is a homeomorphism on the image   $K \colon =\operatorname{Im}(\psi)\subset [0,1] \backslash \mathbb{Q}$. Now let $f\colon K \to \mathbb{R}$, $f = \phi\circ \psi^{-1}$, and extend $f$  with Tiezte to $[0,1]$.
$\bf{Added:}$ Inspired by the solution of @Thomas Andrews, here is another solution:
$$f(x) = \left[\frac{x}{2\pi}\right]\cdot\sin x$$
I'll leave the verification as an exercise.
$\bf{Added:}$ Probably a lot of hightly oscilating functions ( like $e^x \sin x$) satisfy the property but checking that can be delicate.  However, it is not that difficult for the function
$$f(x) = x \cdot \sin 2\pi x$$
(inspired by the observation of @Olivier Roche:, )
Indeed, the fibres of $f$ are infinite, but in each fibre there are only finitely many rational numbers-- this because the degree of the algebraic number $\cos 2 r \pi$ is  $\frac{1}{2} \phi(m)$, where $m$ is the denominator of $r$. Now $\phi(m) \to \infty$ as $m\to \infty$.
A: Each number $x$ in $[0,1]$ can be represented as $\sum{\frac{a_k}{2^k}}$ where $a_k = 0$ or $1$. Define $f(x) = \sum{\frac{a_{2k+1}}{2^k}}$. Then it is easy to see that $f$ is continuous and onto $[0,1]$. Further, for any point $y\in [0,1]$ there are uncountable many $x$ such that $f(x) = y$. Hence, there must be an irrational $x$ with this property. Lastly, one extends $f$ on other intervals by proper shift.
