TITLE: Is the following function continuous at $x = 0$?
QUESTION [6 upvotes]: Define $f: \mathbb{R} \to \mathbb{R}$ by
$$ f(x) = \cases{
x - 1 \ \ \text{ if } x \in \mathbb{Q}
\\1 - x \ \ \text{ if } x \not\in \mathbb{Q}.
}$$
I'm trying to prove whether or not $f$ is continuous at $x = 0$. 
Here's my strategy so far. 
Proof Sketch
Construct a sequence of irrationals $\{x_n\}$ such that $\{x_n\} \to 0$ (which can be done as a result of the density of $\mathbb{R} \setminus \mathbb{Q}$ in $\mathbb{R}$).
Now examine $\lim_{n \to \infty} f(x_n) = 1 - 0 = 1$. However $f(0) = 0 - 1 = -1$, since $0$ is a rational number. Thus, we have found a sequence converging to $0$ such that $\lim_{n \to \infty} f(x_n) \neq f(0)$, and, as a result, $f$ is discontinuous at $x = 0.$ 
Update: Proving $f$ continuous at $x = 1$
We wish to show that for every $\epsilon > 0$ there exists $\delta > 0$ such that $$|x - 1| < \delta \implies |f(x) - f(1)| < \epsilon.$$
Since $x = 1$ is rational, $f(1) = x - 1 = 1 - 1= 0$. So, equivalently, we need
$$|x - 1| < \delta \implies |f(x)| < \epsilon.$$
We now take two cases. Assume first that $x$ is rational, so $f(x) = x - 1$. Now set $\delta = \epsilon.$ Clearly,
$$|x - 1| < \delta = \epsilon \implies |f(x)| = |x - 1| < \epsilon.$$  
The next case is similar. Assume $x$ is irrational, so $f(x) = 1 - x.$ Again, set $\delta = \epsilon.$ We have
$$|x - 1| < \delta  = \epsilon \implies |x - 1| = |1 - x| < \epsilon.$$

REPLY [2 votes]: Yes (to your question of whether you gave a valid way to show it is discontinuous at $0$, not to the question in the title).
A modification of this argument could be given to show that $f$ is discontinuous at each $x\neq 1$.  (If $x$ is irrational, you would instead use a sequence of rational numbers converging to $x$.)  But you might want to also think about how to prove that $f$ is continuous at $x=1$.

On the new question about continuity of $x=1$: The argument is mostly good, but the logic of the presentation is not entirely satisfactory in my opinion.  After a given $\varepsilon>0$ is hypothesized, existence of a single $\delta>0$ needs to be demonstrated that works, rather than assigning $\delta$ in separate cases.  This is practically a very minor matter here, especially because the $\delta$ you chose was the same in both cases (and thus this might seem pedantic), and even more generally, if there are a finite number of cases, you could take $\delta$ to be the minimum of the separate "$\delta$"s.  But to present the conclusion in the correct logical order, you could set $\delta =\varepsilon$ up front, then show that regardless of whether $x$ is rational or irrational, this choice of $\delta$ yields $|x-1|<\delta\implies |f(x)-f(1)|<\varepsilon$ (so that it is clear up front that we are talking about one $\delta$).
Given $\varepsilon>0$, let $\delta =\varepsilon$.  Regardless of rationality of $x$, $|f(x)-f(1)|=|x-1|$, so $|x-1|<\delta$ implies $|f(x)-f(1)|=|x-1|<\delta =\varepsilon$.