Continuous open/closed surjection $p : \mathbb{R} \to \mathbb{Z}$ I am trying to solve the following problem.
I have shown that the following collection of subsets of $\mathbb{Z}$ is a base for a topology $\tau$ on $\mathbb{Z}$: 
$\mathbb{B} =$ { {$2k + 1$} : $k \in \mathbb{Z}$} $\cup$ { {$2k-1, 2k, 2k+1$} : $k \in \mathbb{Z}$}. 
Now, where $\mathbb{R}$ has the usual topology and $\mathbb{Z}$ has this topology $\tau$, I want to find a continuous open or closed surjection $p : \mathbb{R} \to \mathbb{Z}$. But I have been unable to find one so far; the floor and ceiling functions are surjective but not continuous. 
Any ideas or hints would be appreciated!
 A: Let
$$p(x) = \begin{cases} 2k &, x = 2k \\ 2k+1 &, 2k < x < 2k+2, \end{cases}$$
where $k\in \mathbb{Z}$. Then $p$ is continuous. At $x = 2k,\, k\in \mathbb{Z}$, the smallest open set containing $p(x)$ is $U = \{2k-1,2k,2k+1\}$, and $p^{-1}(U) = (2k-2,2k+2)$ is a neighbourhood of $x$. At $x \in \mathbb{R}\setminus 2\mathbb{Z}$, $p$ is constant on a neighbourhood of $x$, so $p$ is continuous at $x$.
$p$ is also open. If $U\subset \mathbb{R}$ is open and contains $2k$, then $p(U) \supset \{2k-1,2k,2k+1\}$, so is a neighbourhood of $p(2k)$. For $x \in U\setminus 2\mathbb{Z}$, $\{p(x)\}$ is already open.
A: Here’s a way to approach a solution somewhat systematically.
Suppose that $p:\Bbb R\to\Bbb Z$ is a continuous surjection, where $\Bbb Z$ has the topology $\tau$. For $n\in\Bbb Z$ let $A_n=p^{-1}[\{n\}]$; $A_n$ is open for each odd $n$ and closed for each even $n$, and $\{A_n:n\in\Bbb Z\}$ is a partition of $\Bbb R$. This suggests that making the sets $A_n$ alternately open and closed intervals might work. Let’s try setting $A_n=(n,n+1)$ if $n$ is odd, and $A_n=[n,n+1]$ if $n$ is even. Equivalently, this is defining $p$ by
$$p:\Bbb R\to\Bbb Z:x\mapsto\begin{cases}
\lfloor x\rfloor,&\text{if }x\in\Bbb R\setminus\Bbb Z\\
x,&\text{if }x\in\Bbb Z\text{ and }x\text{ is even}\\
x-1,&\text{if }x\in\Bbb Z\text{ and }x\text{ is odd}\;. 
\end{cases}$$
If $n\in\Bbb Z$ is even, then $A_{n-1}\cup A_n\cup A_{n+1}=(n-1,n+2)$ is open in $\Bbb R$, and if $n$ is odd, then $A_n=(n,n+1)$ is open in $\Bbb R$, so $p$ is continuous. Let $I=(a,b)$ be any open interval in $\Bbb R$. Then $p[I]$ is an interval in $\Bbb Z$ whose smallest element is $\lfloor a\rfloor$ and whose largest element is $\lfloor b\rfloor$. Unfortunately, this need not be open: for that we want these endpoints to be odd integers. And that can be arranged: instead of taking the endpoints of $A_n$ to be consecutive integers, we can take them to be consecutive odd integers: $A_n=(2n-1,2n+1)$ if $n$ is odd, and $A_n=[2n-1,2n+1]$ if $n$ is even, with the corresponding modification of $p$. I’ll leave it to you to fill in the details of the modification.
