The following is a nice proof from Osborne and Rubinstein's Models in Microeconomic Theory. We want to prove that
Every preference relation on a finite set can be represented by a utility function.
Let $X$ be a finite non-empty set and let $\succeq$ be a preference relation on $X$. Next, let $Y_0 = X$ and let $M_1$ be the set of alternatives minimal with respect to $\succeq$ in $Y_0$, which is non-empty since it can be shown that any finite non-empty set admits at least one maximal and at least one minimal element with respect to a preference relation.
Next, for $k \geq 1$, define $Y_k = Y_{k - 1} \setminus M_k$ as long as $Y_{k - 1}$ is non-empty. As before, $M_k$ is the set of alternatives minimal with respect to $\succeq$ on $Y_{k - 1}$, and is non-empty as long as the latter is also non-empty.
Since by assumption $X$ is finite, there exists $K \in \mathbb{N}$ such that $Y_K$ is empty (while $Y_{K - 1}$ is non-empty). This means that every $x \in X$ is an element of $M_k$ for some $k = 1, 2,\dots, K$.
Now define $u : X \to \mathbb{R}$ given by $u(x) = k$ for all $x \in M_k$ for some $k = 1, 2,\dots, K$. We claim that $u$ is a utility function for $\succeq$, i.e. for any alternatives $a$ and $b$ we have $a \succeq b$ if and only if $u(a) \geq u(b)$. To see that, note that $u(a) = u(b)$ if and only if $a$ and $b$ are both minimal with respect to $\succeq$ in $Y_{u(a) - 1}$, i.e. $a \succeq b$ and $b \succeq a$, so $a \sim b$.
Also, we have $u(b) > u(a)$ if and only if $a$ is minimal with respect to $\succeq$ in $Y_{u(a) - 1}$ but $b$ is not, hence $b \succeq a$ but $a \nsucceq b$ and so $b \succ a$. $\square$
Hope this helps.