Solution (source code)

= Solution

By the Heine–Borel theorem a subset of $\mathbb R$ is <compact> exactly when it is closed and <bounded>. Consequently the nonempty <compact> <intervals> are exactly $\boxed{[a,b]\quad(-\infty<a\le b<\infty)}$. This includes the degenerate <interval> $[a,a]$. The empty <interval> is <compact> as well; nonclosed <bounded> <intervals> and all unbounded <intervals> fail the criterion.