$f(x)\in \mathbb Q,$ if $x\not\in \mathbb Q$ and $f(x)\not\in \mathbb Q$, if $x\in \mathbb Q$. 
$f(x)\in \mathbb Q,$ if $x\not\in \mathbb Q$ and $f(x)\not\in \mathbb Q$, if $x\in \mathbb Q$. Can $f$ be continuous?

I have tried using the sequential definition of continuity on rational and irrational sequences, but not getting anywhere.
Any suggestions?
 A: No, it is not possible for $f$ to be continuous.
Suppose that there was a continuous $f$. Then $f(\mathbb{Q})$ has countable image, since $\mathbb{Q}$ is countable. And $f(\mathbb{R}\backslash \mathbb{Q})$ has countable image, since its image is a subset of the rationals. And so $f(\mathbb{R})$ is countable.
On the other hand, since $\mathbb{R}$ is connected and $f$ is continuous, then $f(\mathbb{R})$ is connected. But the only connected countable sets are singletons, $\{x\}$, which is clearly a contradiction. $\diamondsuit$

As an alternate end, which doesn't use connectedness (directly, that is) but instead uses the Intermediate Value Theorem:
Call $f(0) = a$, which is some irrational, and $f(\pi) = b$, which is some rational. Since $f$ is continuous, the image of $f$ must contain every number in the interval $[a,b]$. However there are uncountably many points on$[a,b]$, while the image of $f$ has only countably many points. We have a contradiction. $\diamondsuit$
A: Clearly image of the given continuous function is countable. Again it assumes rational and irrationals both values and so by intermediate value theorem for continuous functions image of $f$ assumes uncountable values, which is a contradiction. So no such function exists. 
