Let $(X,d)$ be a metric space.
(a) Suppose that every function $f:(X,d)\rightarrow(X,d)$ is continuous. Prove that any subset of $X$ is open in $(X,d).$
(b) Suppose that the only continuous functions $f:(X,d)\rightarrow (\mathbb{R},|\cdot|)$ are constant functions. Prove that $X$ contains only one point.
The following details are my attempts on part (a) and (b) :
(b) For fixed $y\in X$. Consider the function $f(x)=|x-y|$ where $x\in X$ and $x\neq y$. We see that $f$ is continuous using the reverse triangle inequality. The function $f$ will be constant only when $f(x)=0$ which means that $x=y.$ Thus $X$ is a one-point set. I am not sure this approach will be alright or not.
For part (a), We treat $X$ and $\emptyset$ separately which is obvious that they are open in $X$. Given arbitrary open set $U$ in $X$.... I tried to assert by contradiction but I made no progression. Any ideas are all welcome. Thanks!
For (b), you have the right idea, but remember that in a metric space, there may not be any notion of addition, subtraction, or absolute value, so $|x-y|$ may not make any sense. Instead, use the metric $d(x,y)$. Show that it is continuous and non-constant if there is more than one point, using the reverse triangle inequality as you say.
For (a), Consider an arbitrary set $A\subset X$. Let $p$ and $q$ be distinct points in $X$. By hypothesis, the function $$f(x)=\begin{cases} p & x\in A\\ q & x\not\in A\end{cases}$$ is continuous. How does this imply that $A$ is open? And what if $X$ has only one point so that we cannot choose distinct $p$ and $q$?