Show that f is continuous on x if and only if x is irrational 
Let $f : [0, 1] → R$ be given by the formula
$f(x) = \frac{1}b$ if $x = \frac{a}b$, where $a$ and $b$ have no common factor,
$f(x) = 0$ if $x$ irrational.
Show that $f$ is continuous at $x$ if and only if $x$ is irrational. (Hint: Use the
density properties of rationals and irrationals.)

My attempt: Let $\epsilon > 0$. Suppose $x$ is irrational, then $f(x) = 0$.
$|x-x| < \delta$
$|f(x) - x| = |-x| = x$
So we can choose $\delta = \epsilon$ so that $\epsilon > x$ (I'm unsure of this part).
Suppose $x$ is rational, $f(x) = \frac{1}b$. We want to show that is discontinuous. Suppose there is a $\delta$ that works for $|\frac{1}b-x| < \epsilon$. Let $\epsilon = \frac{1}2$. Let $x= \min(\delta, \frac{3}4)$
$|\frac{1}4 - \frac{3}4| = |-\frac{1}2| = \frac{1}2$
And $1/2$ is not greater than a $1/2$. So it is a contradiction.
 A: For $x_0\in [0,1]$, we want to show $f$ is continuous at $x_0$ if and only if $x_0$ is irrational.

 First, suppose $x_0\in [0,1]$ is rational.

Then $f(x_0) > 0$. 

Since the irrationals are dense in $[0,1]$, there is a sequence $t_1,t_2,t_3,... \in [0,1]$ of irrational numbers such that $t_n$ approaches $x_0$, as $n$ approaches infinity.

So we have ${\displaystyle{\lim_{n\to \infty}t_n}}=x_0$, 
but
${\displaystyle{\lim_{n\to \infty}f(t_n)}}=0 \ne f(x_0)$, hence $f$ is not continuous at $x_0$.

Next, suppose $x_0\in [0,1]$ is irrational.

Necessarily, $x\in (0,1)$.

Fix $\epsilon>0$.

Choose an integer $B > {\large{\frac{1}{\epsilon}}}$.

There are only finitely many rationals in $(0,1)$ with denominators less than $B$, hence, for some $\delta > 0$, we have an interval $(x_0-\delta,x_0+\delta) \subseteq (0,1)$ which contains none of them.

If $x\in (x_0-\delta,x_0+\delta)$, and $x$ is irrational, then $f(x) = 0$.

If $x\in (x_0-\delta,x_0+\delta)$, and $x$ is rational, then $0 < f(x) \le {\large{\frac{1}{B}}} < \epsilon$.

In either case, $|f(x)| < \epsilon$.
\begin{align*}
\text{Then}\;\;&|x-x_0| < \delta\\[4pt]
\implies\;&x\in (x_0-\delta,x_0+\delta)\\[4pt]
\implies\;&|f(x)| < \epsilon\\[4pt]
\implies\;&|f(x)-f(x_0)| < \epsilon\\[4pt]
\end{align*}
hence $f$ is continuous at $x_0$.
A: Firstly we need to restrict the domain to $(0,1]$ or the function is not well-defined.
For any $x$ we can say $f$ is continuous at $x$ if for all sequences $(x_n)_{n=1}^\infty$ where $x_n \rightarrow x$ as $n \rightarrow \infty$ then $f(x_n) \rightarrow f(x)$ as $n \rightarrow \infty$. This defintion should be easier to use.
Suppose $x$ is irrational and $x_n \rightarrow x$ as described. If only finitely many $x_n$ are rational we note that $f(x_m)=0$ for high enough $m$ so we may assume without loss of generality that each $x_n$ is rational and $x_n=\frac{a_n}{b_n}$ where $a_n$ cannot divide $b_n$. If $b_n$ is bounded then this will force $b_m =b$ and $a_m =a$ for high enough $m$ (why is this true?) and $x=\frac{a}{b}$, thus $(b_n)_{n=1}^\infty$ is unbounded. If $(b_n)_{n=1}^\infty$ has a bounded subsequence then $(x_n)$ would have a limit point that is rational by a similar reason given above (yet again, why must this hold?) and so $b_n \rightarrow \infty$. It now follows that $f(x_n) = b_n \rightarrow 0 = f(x)$ as required.
Now suppose $x$ is rational. We now note that are the irrationals are dense in $\mathbb{R}$ there exists a sequence of irrationals $(x_n)$ where $x_n \rightarrow x$, then $f(x_n)=0$ and $f(x_n)$ doesn't converge to $f(x) \neq 0$, thus $f$ is not continuous at $x$.
A: Hint if $x= a/b \in [0, 1]$ is rational, then, because the irrational numbers in $[0, 1]$ are dense, there are irrational numbers $y$ arbitrarily close to $x$ such that $|f(x) - f(y)| = |1/b -0| = 1/b$. If $x \in [0, 1]$ is irrational, then for any given $B$, the rational numbers in the interval $(x - 1/B, x + 1/B)$ all have the form $a/b$ with $b > B$.
A: Let $x_0$ an irrational number in $[0,1]$. You have to show that $\lim_{x\to x_0}f(x)=f(x_0)=0$. This is obvious for irrational $x$s, so all you have to prove is
$$\lim_{\substack{x\to x_0\\x\in\mathbf Q}}f(x)=0.$$
In terms of $\varepsilon$ and $\delta$, this means that, for any  $\varepsilon>0$, there exists $\delta>0$  such that
$$\biggl|\frac ab -x_0\biggr|<\delta \implies 0<\frac1b <\varepsilon,\enspace\text{i.e. }\; b>\frac1\varepsilon. $$
Indeed, there is only a finite number of positive integers $\le\dfrac1\varepsilon$. Therefore, by the  Archimedes property, the interval $[0,1]$ contains only a finite number of rational numbers $\dfrac ab$ in irreducible form with denominator  $\le\dfrac1\varepsilon$.
Choose  $\delta>0$  small  enough so the interval $(x_0-\delta, x_0+\delta)$ contains none of these fractions. Then all rational numbers $\dfrac ab$ in this interval have denominator $ b>\dfrac1\varepsilon$, hence
$$f\Bigl(\frac ab\Bigr)=\frac1b<\varepsilon.$$
The other way (continuous at $x$ implies $x$ irrational) is obvious  by contrapositive and density of the irrational numbers.
