Let $f:(\mathbb{R}\setminus\mathbb{Q})\cap [0,1]\to \mathbb{Q}\cap [0,1]$. Prove there exists a continuous$f$.

Hint: let $a_1=0, a_2=1/2, a_3=2/3, \ldots, a_i = 1-1/i$ and define $f$ to be constant on $(\mathbb R \setminus \mathbb Q) \cap [a_i, a_{i+1}]$.


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.