Real Analysis HW Question involving continuity. Suppose $f:[a,b] \rightarrow \mathbb{R}$ is two-to-one. Find an example of a two-to-one function and show that no such function can be continuous. I have had issues doing either of these. I feel it has something to do with $[a,b]$ being compact. So 1. I know that the continuous image of a compact set is compact, 2. continuous functions on compact sets are uniformly continuous, and 3. I know sequential compactness and most other "equivalent" forms of continuity. Can anyone drop me a hint?
 A: Here's a suggestion for a different proof from the one Jason DeVito pointed out. It is not necessarily easier, but uses the nested intervals lemma, which may be a plus. 
Suppose $f$ is continuous and 2-to-1. Let $$t = \frac12(\min_{[a,b]} f + \max_{[a,b]} f)$$  The set $\{x:f(x)=t\}$ consists of exactly two points, say $a_1$ and $b_1$ with $a_1<b_1$. On the interval $(a_1,b_1)$ we have either $f>t$ or $f<t$. Assume $f>t$ on this interval (the other case can be turned into this one by flipping $f$). 
Let $$t_1 = \frac12(\min_{[a_1,b_1]} f + \max_{[a_1,b_1]} f)$$ Again, the set $\{x:f(x)=t_1\}$ consists of exactly two points, say $a_2$ and $b_2$ with $a_1<a_2<b_2<a_1$. This time, we know that on the interval $(a_2,b_2)$ the inequality $f>t_1 $ holds (why?). Continuing this process, we get a nested sequence of intervals $[a_n,b_n]$ such that $[a_n,b_n]=\{x:f(x)\ge t_{n-1}\}$. The intersection of these intervals is precisely the set of absolute  maxima of $f$ (why?), and being the intersection of nested intervals, it is either infinite or a single point.
