Show that the function $f:X\to \mathbb R$ defined by $f(x)=d(x,A)$ is continuous. 
Let $d$ be a metric on $X$ and let $A$ be any arbitrary subset of $X$. Show that the function $f:X\to \mathbb R$ defined by $f(x)=d(x,A)$ is continuous.

Let $p\in X$. We want to show that for any open set $S$ containing $f(p)$, there exists an open neighbourhood of $p$, denoted by $O$, such that $f[O]\subset S$. If $p\in$ int $A$, then there exists an open set $O \subset A$ containing $p$. Clearly $f[O] \subset S$ since $O$ is a subset of $A$ and $f[O]= \{ 0 \}= \{f(p) \} \subset S$. If $p\in \partial A$ (boundary of A) or $p\in$ ext $A$, the situation is much harder. The reason for this being hard is that the function $d$ is not specific and is defined in terms of infimum. 
 A: For all $a\in A, x,y\in X$ $$d(x,A) \leq d(x,a) \leq d(x,y)+d(y,a).$$ Equivalently, $$d(y,a)\geq d(x,A) - d(x,y).$$
Thus $$ d(y,A)=\inf_{a\in A} d(y,a) \geq \inf_{a\in A}\left( d(x,A)-d(x,y) \right) = d(x,A)-d(x,y).$$
Therefore $d(x,A)-d(y,A)\leq d(x,y),$ and interchanging $x,y$ gives the desired result.
A: Don't try so hard. We have, for any $a,\in A$ and $x,x'\in X$ that $$d(x,a)-d(x',a)\leqslant d(x,x')$$ $$d(x',a)-d(x,a)\leqslant d(x',x)$$
Using the definition of $\inf$, you should get $d(x,A)-d(x',A)\leqslant d(x,x')$ and $d(x',A)-d(x,A)\leqslant d(x',x)$. In particular your function is Lipschitz, so uniformly continuous.
ADD A not so well known inequality is the quadrilateral inequality
$$|d(x,x')-d(z,z')|\leqslant d(x,z)+d(x',z')$$
A: Lemma: $\forall x,y \in X: f(x) - f(y) \le d(x,y)$
(Intuition: this is the triangle inequality, but with the whole of the set $A$ in place of one of the points: $d(x, A) \le d(x,y) + d(y,A)$)
Proof:
$f(x) - f(y) = d(x, A) - d(y, A) = d(x, A) - \inf_{a \in A} d(y, a) = \inf_{a \in A}(d(x, A) - d(y, a))$
$ \le \inf_{a \in A}(d(x, a) - d(y, a))$ since $d(x,A) \le d(x,a)$
$ \le \inf_{a \in A}d(x, y)$ (triangle inequality, $d(x,a) \le d(x,y) + d(y,a)$)
$ = d(x,y)$
Proving the lemma.
Then $f(y) - f(x) \le d(y, x) = d(x, y)$ since $d$ is symmetric, so:
$|f(x) - f(y)| \le d(x,y)$

Now we will show that the inverse image under $f$ of an open set is open, that is to say $f$ is continuous.
Let $U \subseteq \mathbb{R}$ be an open set.
Let $x \in f^{-1}(U)$, that is $f(x) \in U$, so there exists an open ball $B$ (of radius $r$, say), around $f(x)$ that is a subset of $U$.
Let $B'$ be the open ball around $x$ with radius $r$. Then for $y \in B'$ we have $d(x, y) < r$, so $|f(x) - f(y)| \le d(x, y) < r$, hence $f(y) \in B$. So $B' \subseteq f^{-1}(B) \subseteq f^{-1}(U)$
So every element of $f^{-1}(U)$ has an open ball around it in $f^{-1}(U)$, hence $f^{-1}(U)$ is open.
