Problem $2.1.1$, Berkeley Problems in Mathematics ($3$rd Edition) Berkeley Problem in Mathematics $2.1.1$ is the following: Let $f$ be a function from $\mathbb{R}^n$ to $\mathbb{R}^n$ such that:
(a) If $K$ is a compact subset of $\mathbb{R}^n$, then $f(K)$ is a compact subset of $\mathbb{R}^n$.
(b) If $K_1$, $K_2$,... is a decreasing sequence of compact subset of $\mathbb{R}^n$, then $f(\cap_{i=1}^{\infty}K_i) = \cap_{i=1}^{\infty}f(K_i)$.
Show that $f$ is continious.
The solution can be written as follows: We want to show that $f$ is continious on $\mathbb{R}^n$. Thus, fix $x_0 \in \mathbb{R}^n$. We need to show that $f$ is continious at $x_0$, i.e for all $\epsilon>0$, there exists a $\delta>0$ such that $|x-x_0| < \delta$ implies that $|f(x) - f(x_0)| < \epsilon$.
Given $\epsilon >0$, let $B$ be the ball centered at $f(x_0)$ with radius $\epsilon$. Define $K_i$ be the ball centered at $x_0$ with radius $\frac{1}{i}$ for $i= 1,2,...$. Note that, each $K_i$ is a compact subset of $\mathbb{R}^n$. Also, $\cap_{i=0}^{\infty} K_i = x_0$.(Nested Interval Property). By, (b) we can conclude that $\cap_{i=0}^{\infty}f(K_i) = f(x_0)$.
Now, consider the sets $A_i:= (\mathbb{R}^n - B) \cap f(K_i)$. Clearly, $A_i$s are compact subsets of $\mathbb{R}^n$ by (a) and $A_i$s are decreasing. Moreover, $\cap_{i=1}^{\infty} A_i = \emptyset$.This means that, there exist a natural number $m$ such that $(\mathbb{R}^n - B) \cap f(K_m) = \emptyset$. In other words, if $|x-x_0| < \frac{1}{m}$, then $|f(x) - f(x_0)| < \epsilon$. As a result, $f$ is continious at $x_0$, since $x_0$ is arbitrary, $f$ is continious at  $\mathbb{R}^n$.
We did use both assumptions (a) and (b). However, I could not find a counter-example when either assumption (a) or assumption (b) is removed. Is there an easy counter-example?
Thanks in advance.
 A: Here is an example for when assumption $(a)$ holds, but $(b)$ is dropped. For simplicity, consider $n = 1$. The argument can be easily generalized to $\mathbb R^n$.
Consider $f = \chi_{\Bbb Q}$, the indicator function of $\mathbb Q \subset \mathbb R$. We have $f(x) = 1$ for $x\in \Bbb Q$, and $f(x) = 0$ for $x\notin \Bbb Q$. $f$ maps every subset of $\Bbb R$ to a compact set ($\{0\}$, $\{1\}$ or $\{0,1\}$), so in particular it maps compact sets to compact sets. However, $f$ is not continuous. The second condition $(b)$ fails. To see this, consider a sequence of compact sets $\{K_n\}_{n=1}^\infty$ of $\Bbb R$, given by $K_n = \left[ 0, \frac1n\right]$ for every $n\ge 1$. Clearly, $f(K_n) = \{0,1\}$ for every $n\ge 1$, so $\bigcap_{n=1}^\infty f(K_n) = \{0,1\}$. However, $\bigcap_{n=1}^\infty K_n = \{0\}$, which gives $f(\bigcap_{n=1}^\infty K_n) = \{1\}$. Thus, $\bigcap_{n=1}^\infty f(K_n)  \ne f(\bigcap_{n=1}^\infty K_n)$.
Note: To generalize this to $\mathbb R^n$, consider the indicator function of $\mathbb Q^n$, and the sequence of compact sets $$K_n = \underbrace{\left[ 0, \frac1n\right] \times \left[ 0, \frac1n\right] \ldots \times \left[ 0, \frac1n\right]}_{n\text{ times}}$$

In some other answers, discontinuous functions $f:\Bbb R^n\to\Bbb R^n$ for which $(b)$ holds, but $(a)$ does not have been constructed.

Extra: Here is a somewhat related result you might be interested in.

Theorem: If $X$ is Hausdorff, locally connected and Fréchet, and $Y$ is Hausdorff (e.g. if $X=Y=\mathbb R$), then any function $f:X\to Y$ which maps compact sets to compact sets, and connected sets to connected sets, is continuous.

The converse is trivially true, so this is in fact a characterization of continuous maps from Hausdorff, locally-connected, Fréchet spaces to Hausdorff spaces. Amazing, isn't it?
A: To add to epsilon-emperor's answer, there is an easy way to construct counterexamples for "b), but not a)":
For every injective function $f : \mathbb{R}^n \to \mathbb{R}^n$, continuous or not, and arbitrary families of subsets $\{A_i\}_{i = 1}^\infty$ of $\mathbb{R}^n$, one has $f( \bigcap_{i =1}^\infty A_i) = \bigcap_{i=1}^\infty f(A_i)$.
As such, b) is fulfilled by every injective function. But of course, discontinuous injective functions exist, such as
$$f : \mathbb{R} \to \mathbb{R}, \quad x \mapsto \begin{cases} x + 1, & x > 0 \\ x, & x \leq 0,\end{cases}$$
and it is also easy to verify by hand that it does not fulfil a), e.g. $f([0,1]) = \{0\} \cup (1,2]$ is not compact.
A: For (b) but not (a) consider $f:\mathbb{R}\to\mathbb{R},t\mapsto t\,\chi_{]-1,1[}(t)$. It's straightforward to generalize to higher dimensions.

Added: In case there is confusion $f(t)=\begin{cases}t,\text{ if } -1<t<1\\ 0,\text{ otherwise}\end{cases}$.
