TITLE: Can we find a function $f:\mathbb{R}\rightarrow \mathbb{R}$ that is open, closed, but not continuous?
QUESTION [10 upvotes]: The question is described in the title. To clarify, I'm looking for an example where the domain of such a function is $\mathbb{R}$, so the example here will not work.
The highest upvote answer here gives an example of discontinuous open map from $\mathbb{R}$ to $\mathbb{R}$, but that map can hardly be closed (closed set does not need to contain any interval!). I have difficulty generalize the construction and know very little about any sufficient condition that leads to closed map without continuity (piecewise constant will work, but that kind of maps cannot be open!).
I'll appreciate any example, non-constructive prove/disprove, or any reference that covers this.
*In case I need to clarify this, we use std. metric topology on $\mathbb{R}$

REPLY [4 votes]: No such function exists.
Assume that $f((a,b))$ is a bounded open set. Then $f((a,b))= (c,d)$ for some $c,d\in \mathbb{R}$. Indeed, $f((a,b))$ is an open set hence of the form $\bigcup (a_n,b_n)$ however $f([a,b])$ has at most two more points than $f((a,b))$, so  we conclude.
Claim: if $f((a,b))= (c,d)$ then $f$ is continuous and strictly monotonic on $(a,b)$.
Proof: Firstly, we will show that $f$ is injective. Indeed assume that $f(x_1)= f(x_2)$ for some $x_1,x_2\in (a,b)$. Then take the $f((x_1,x_2))=(c_1,d_1) $ for some $c_1,d_1$, a contradiction since $f( [x_1,x_2] )$ needs two points to be closed. Now, since $f$ has the IVT propoerty and it is injective it is strictly monotonic and continuous.
We will argue by contradiction. Assume that $f$ is not continuous at $x_0$, and set $V_n=( x_0-1/n,x_0+1/n  )$. Now, the claim implies there are $z_n<w_n$ such that $f(V_n )=(-\infty ,z_n)\bigcup (w_n,\infty) $ where $z_n$ or $w_n$ can possibly take the value $\pm \infty$. Also, notice that $w_n$ is increasing and $z_n$ is decreasing. 
First case, one of the $z_n,w_n$ converges (to a finite limit). WLOG assume that $w_n \rightarrow w$. Now, pick a number $\beta$ in $(w,\infty)$ that is different from $f(x_0)$. We can find a sequence $p_n\in V_{n-1}\setminus V_n$ such that $f(p_n)=\beta +1/n$. A contradiction since the closed set $\{x_0\}\bigcup \{p_n|n\in \mathbb{N}\}$ gets mapped via $f$ to $\{f(x_0)\}\bigcup \{\beta +1/n|n\in \mathbb{N}\}$ which is not closed.
In the second case, we have $z_n \rightarrow -\infty$ and $w_n \rightarrow\infty$. This is a contradiction since the previous implies $\bigcap_{n \in \mathbb{N}}f(V_n)= \emptyset$, however $\bigcap_{n \in \mathbb{N}}f(V_n)$ always contains $f(x_0)$.