Let $S= \{0\} \cup \{ \frac{1}{n} : n \in \mathbb{N} \}$ and define $f: \mathbb{R} \to \mathbb{R}$ as $f(x)= \min \{ |x-t| : t \in S \}$
a) Prove that $|f(x)-f(y)| \leq |x-y|$ for any $x,y \in \mathbb{R}$
b) Find the antiderivatives of $f$
I obtained the following form for the function: $$f(x)= \begin{cases} -x, \quad &x \leq 0 \\ x-\frac{1}{n+1}, \quad &\frac{1}{n+1} \leq x \leq \frac{1}{2}(\frac{1}{n+1}+\frac{1}{n}) \\ \frac{1}{n}-x, \quad &\frac{1}{2}(\frac{1}{n+1}+\frac{1}{n}) < x < \frac{1}{n} \\ x-1, \quad &x \geq 1 \end{cases}$$
I then tried to prove the inequality from a) considering many cases for $x$ and $y$, but there are many possibilities. For the antiderivatives, I tried to combine the antiderivatives for each of the 4 branches of the function, but again, the calculations are messy.
Let $S$ be a subset of $\mathbb{R}$.
For any $\epsilon > 0$ there is $s'\in S$ such that $|x-s'| \leq f(x) + \epsilon$. We know that $f(y) \leq |y-s'| = |y-x+x-s'|\leq |y-x|+f(x)+\epsilon$. Since this holds for any $\epsilon > 0$ we have $f(y) \leq f(x) + |y-x|$.
For any $\delta > 0$ there is $t'\in S$ such that $|y-t'| \leq f(y) + \delta$. Analogously, $f(x) \leq |x-t'| = |x-y+y-t'|\leq |x-y|+ f(y) + \delta$. Since this holds for any $\delta > 0$ we have $f(x)\leq f(y) + |y-x|$.
Thus we have $$\begin{equation} f(x)-f(y) \leq |x-y|\\ f(y)-f(x) \leq |y-x|. \end{equation}$$ Thus $|f(y)-f(x)|\leq |y-x|$.
No let $S$ be defined as in your example and you are done.