If $S$ is compact then for every $x \in \mathbb{R}$ there is $s \in S$ such that $|x-s| = d(x,S)$ $d(x,S) = \inf_{s \subset \mathbb{R}}\{|x-s|: s \in S\}, x\in \mathbb{R}$
I did notice this question was asked before, but most people were asking for tips or completely solve it for them. I want to get critique on my work as I seem to be the only to have attempted it.
How I went about it:
If S is compact and $x \in \mathbb{R}$, S is closed and bounded.
Let $x \in \mathbb{R}$. Then $\exists y \in S$ such that $|y-s| = d(x,S)$, where $d(x,S) = \inf\{|x-s|, s \in S \}$
Consider the function ($x \in \mathbb{R}$ is fixed)
$g: S \rightarrow \mathbb{R}$
$g(s) = |x-s|$
This is a continuous function on a compact set. So it contains its infimum or can be minimum in this case.
$\exists y \in S$ such that $g(y) = \inf\{|x-s|, s \in S \}$
$|g(s) - g(t)| = |x-s| - |x-t| \leq |s-t|$
Sorry as I'm writing this I'm getting confused myself. Tips are plenty welcome at this point as my brain is getting fried.
 A: *

*You have stated that since $S$ is a compact set in $\mathbb R$ then it is closed and bounded, but you have not used this fact in your proof. Another fact you have missed is that the absolute value is a continuous function when one of the points is fixed. Therefore you could have proved this claim for every subset of the real line with every function, which is wrong. Thus your proof is obviously wrong.

*If $d(x,S)=inf \{|x-s|,s\in S\}$ then you might want to state that $d(x,S)=d_x(s)$ is a continuous function on a compact set for all $x\in\mathbb R$ and build a sequence using the this fact in $S$.

A: Consider the sequence of ${s_n}$ so that $d(x,S)- 1/n < |x - s_n| \le d(x,S)$.  We know such so sequence exist ans $d(x,S)$ is glb so for and $r < d(x,S)$ there exists so $r < |x - s_n|  \le d(x,S0$.  This sequence is cauchy because for all $\epsilon > 0$ we can find $1/n < \epsilon$ so $m, k > n$ implies $|s_m - s_k| < 1/n < \epsilon$. So {$s_n$} converges to some $s$.  And all $s_n \in S$.  $s$ is a limit point of $S$.  As $S$ is closed $s \in S$. But $d(x,S) - 1/n < |x - s| \le d(x,S)$ for all $n$.  So $|x -s| = d(x,S)$.
