[Math] Functions that are continuous only at two points

continuityfunctionsreal-analysis

I need to find a function $f:\mathbb{R}\to\mathbb{R}$ which is continuous only at two points, but discontinuous everywhere else.

How on earth would I go about doing this? I can't think of any function like this.

Thanks in advance.

Edit: I've seen examples including the indicator function for rationals. Is this the only method of finding such functions?

Best Answer

Think of something like $$f(x)=\begin{cases} x^2 & \text{if } x \in \mathbb{Q}\\ x & \text{if } x \in \mathbb{R-Q}\\ \end{cases} $$ This is only continuous at two points, namely where $x^2=x$.