(S,d) is a metric space. A is a subset of S. show that for any closed set B $\in$ Question: 
A. Let $(S,d)$  a metric space. $A$ is a subset of $S$. Function $f$ is defined as
$f: S \to \mathbb{R}$, $f(x) = \inf \{d(x,y) : y\in A\}$ , $\forall x\in S$. How to prove that $f$ is uniformly continuous on $S$?
B. Show that for any closed set $B\in S$ there exists a continuous function $f : S\to\mathbb{R}$ that is $0$ on $B$ and positive elsewhere
Could you correct if there are errors in my proof for A and B?
For A:
Choose points of $A$ whose distance to $x$ is closeset to $f(x)$
(if not, $f(x)$ would not be the infimum). 
Let $z$ be a point in $A$ such that:
$f(x) \le d(x, z) < f(x) + \frac{\epsilon}{2}$
Then, again by the triangle inequality, we have:
$d(y, x) + d(x, z) \ge d(y, z) \ge f(y)$
$\implies d(y, x) + f(x) + \frac{\epsilon}{2} > f(y)$
$\implies d(y, x) + \frac{\epsilon}{2} > f(y) - f(x)$.
Similarly,
$d(y, x) + \frac{\epsilon}{2} > f(x) - f(y)$.
Hence,
$d(y, x) + \frac{\epsilon}{2} > |f(x) - f(y)|$
If we choose $\delta = \frac{\epsilon}{2}$, 
$d(y, x) < \delta = \frac{\epsilon}{2}$
$\implies d(y, x) + \frac{\epsilon}{2} < ε / 2 + ε / 2 = ε$
$\implies |f(y) - f(x)| < \epsilon$
Therefore, $f$ is (uniformly) continuous
(Also I'm not sure whether what I proved here is that $f$ is continuous or that $f$ is uniformly continuous)
For B,
I thought it was really obvious one after solving A.
We can just define a function $f: S\to\mathbb{R}$, $f(x) = \inf \{d(x,y) : y\in A\}$ , $\forall x\in S$. 
Then, if $x\in A$, $f(x)$ will be $0$. 
If $x\notin A$, $f(x) = \inf \{d(x,y) : y\in A\}$, which is not zero.
(do I need to prove this is not zero? maybe I should use that $B$ is closed set?)\, 
It's nonnegative since it is an absolute value, but I'm not sure how to show it is not zero.
 A: Part A seems correct to me. Also for part B your construction is fine. Now you want to show $f(x)>0,$ if $x\notin B$. As you have already figured out that $f\ge 0$, so suppose $f(a)=0$ for some $a\notin B$.
So, $f(a)=\inf\{d(x,a):x\in B\}=0$. So for each $n$, $\exists \ x_n\in B$ such that $d(x_n,a)<{1\over n}$. Hence, $B_r(a)\cap B$ is non empty for all $r>0 \implies a\in \bar{B}=B$ as $B$ closed. Contradiction!
A: Your proof has been discussed, but let me add things because this question is 'classical' in metric space theory I guess. This function $f$ is widely used so it is good to know how things are usually worked out.
More interesting and general than the fact that $f$ is uniformly continuous is that it is $1$-Lipschitz, i.e. for every $x, y \in S$, you have 
$$
|f(x) - f(y)| \le d(x,y).
$$
The proof is very easy ; by the triangle inequality, if you take $x,y \in S$, $z \in A$, then you have 
$$
d(x,z) \le d(x,y) + d(y,z) \quad \Longrightarrow \quad f(x) \le d(x,y) + f(y)
$$
by taking infimums on both sides over $z \in A$. This leads to $f(x) - f(y) \le d(x,y)$. Reversing the roles of $x$ and $y$ gives $f(y) - f(x) \le d(x,y)$, hence you can put an absolute value in there. So it is $1$-Lipschitz. 
Now this function $f$ is associated with the set $A$, so let's denote it by $f_A$. If you are given any closed set $B$, then the function you would be looking for here is of course the function $f_B$. You need the fact that $B$ is closed, and this is an if and only if condition ; the function $f_B$ will be positive on $S \backslash B$ if and only if $B$ is closed. Assume $B$ is not closed ; then $B \subsetneq \overline B$, so you have some point in $\overline B$ which is a limit of points in $B$ but is not in $B$. For this particular point $x \in S \backslash B$, we will have $f_B(x) = 0$ precisely because it is in $\overline B \backslash B$. 
I am particularly fond of this problem because one of my professors and dear friend has been trying for a while to define a topological group structure on the set $\{ f_A \, | \, A \subseteq S, A \text{ closed } \}$ for some 'nice looking metric space $S$ (he doesn't know the criteria required to get some nice results either. This is an interesting piece of research which is still open. I thought I'd give some hints to why this question exists. 
Hope that helps,
