TITLE: Prove that there exists a monotone nondecreasing function $f:[0,1] \rightarrow \mathbb{R}$ discontinuous in rationals
QUESTION [5 upvotes]: Prove that there exists a monotone nondecreasing function $f:[0,1] \rightarrow \mathbb{R}$ discontinuous in rationals of $[0,1]$

I tried to test functions of the type 
$$ f(x)=\begin{cases} \frac{1}{q} & \text{if } x=\frac{p}{q} \mid p,q \in \mathbb{Z}^+ \,\,\, \text{and} \,\,\, \gcd(p,q)=1  \\ x & \text{if } x \not\in \mathbb{Q} \end{cases}$$
which is discontinuous in all rationals, but is not monotone.

REPLY [10 votes]: Since $\mathbb{Q}\cap[0,1]$ is countably infinite, then there's a bijection:
$$\phi:\mathbb{N}\to\mathbb{Q}\cap[0,1]$$
Now define
$$f:[0,1]\to\mathbb{R},\quad f(x)=\sum_{\phi(n)\leq x}2^{-n}$$
Since the geometric series is absolutely convergent, thus rearranging terms does not change the sum, so $f$ is well defined. Clearly $f$ is non decreasing, and
$$\lim_{x\to \phi(n)^-}f(x)=\sum_{\phi(k)<\phi(n)}2^{-n}<f(\phi(n))$$