TITLE: Let $f:(\mathbb{R}\setminus\mathbb{Q})\cap [0,1]\to \mathbb{Q}\cap [0,1]$. Prove there exists a continuous$f$.
QUESTION [8 upvotes]: I'm working on the following problem from N.L. Carother's Real Analysis:

Let $I=(\mathbb{R}\setminus\mathbb{Q})\cap [0,1]$ with its usual metric. Prove that there is a continuous function $g$ mapping $I$ onto $\mathbb{Q}\cap[0,1]$.

My thoughts:
I feel the preimage of open sets definition of continuity will be the easiest way to prove this. If I could show $V\subset \mathbb{Q}\cap [0,1]$ is open for all open sets $V$, and I could show that $f^{-1}(V)$ is open as well, then that would mean $f$ is continuous. I've considered trying to prove that $(\mathbb{Q}\cap [0,1])^c$ is closed, but that doesn't seem much easier. I know $\mathbb{Q}$ is dense in $\mathbb{R}$, and so maybe I can use that to say that $B_{\epsilon}(x)\setminus\{x\}\cap(\mathbb{Q}\cap[0,1])\neq\emptyset$, which would mean every $x\in\mathbb{Q}\cap[0,1]$ is a limit point of $\mathbb{Q}\cap[0,1]$, but I still don't see how this could be helpful.
Any hints on how to proceed would be appreciated. Thanks.

REPLY [2 votes]: OP's space $\ I\ $ doesn't have endpoints and $\ \mathbb Q\cap[0;1]\ $
does. Thus a perfectly elegant solution is very unlikely.
Nevertheless, @DustanLevenstein's
solution is as simple as possible and almost elegant. But elegance has more than one dimension. Thus, I hope that my solution still has something attractive about it. It has the main step, and then another which has to overcome the nuisance caused by the endpoints issue; that second step is
routine.

MAIN STEP:   every irrational number $\ x\in I\ $ admits a unique
chained fraction representation $\ x\ =\ 1/(a+1/(b+ ...)...).\ $ Define
$$ \phi(x)\ :\ I\,\rightarrow\,\mathbb Q_{_{>0}} $$
(where $\ Q_{_{>0}}\ :=\ \mathbb Q\cap(0;\infty))\ $ by
$$ \phi(x)\ :=\ \frac ab $$
This $\ \phi\ $ is clearly a continuous surjection.
THE NUISANCE STEP: There exists a homeomorphism
$\ \psi: Q_{_{>0}}\rightarrow \mathbb Q\cap[0;1]. $ Thus a required continuous
surjection is: $\,\ g\ :=\ \psi\circ\phi\ :\ I\rightarrow\mathbb Q\cap[0;1] .$
That's all.