Algebra 2 Bonus Question This was a bonus question on a test I just took:
Write a function with a domain of all real numbers and a range of only $2$ numbers.
The closest I got to an answer was $f(x)=\frac{x}{|x|}$, which has a range of $\{-1,1\}$, but it fails the part about the domain, because 0 has to be excluded.
Any ideas for the solution to this? Is a solution even possible?
 A: The Intermediate Value Theorem asserts that if $f$ is continuous and $a,b \in \mathrm{range}(f)$ then $[a,b] \subseteq \mathrm{range}(f)$.  Hence, the function must be discontinuous.
This means we are forced to construct a function piecewise (although it might be disguised).  An example is $$f(x)=\begin{cases} 0 & \text{if } x<0 \\ 1 & \text{if } x \geq 0. \end{cases}$$
In fact, every such function will have this form: $$f(x)=\begin{cases} a & \text{if } x \in I \\ b & \text{otherwise} \end{cases}$$ for some $I \subsetneq \mathbb{R}$ and $a,b \in \mathbb{R}$ with $a \neq b$.
We could disguise the piecewise structure, e.g., by taking $$f(x)=(-1)^{\lfloor x \rfloor}.$$
A: $f(x):=0^{|x|}$ is another solution.
A: Another nice example:
$$
f(x)=\lim_{k\to\infty}\Bigl(\lim_{n\to\infty}\bigl(\cos(k!\,\pi x)\bigr)^{2n}\Bigr)
$$
(sources: Nowhere continuous functions, on Wikipedia and Dirichlet function, on Wolfram MathWorld).
This can be written also
$$
f(x)=\begin{cases}
1 & \text{if $x$ is rational},\\
0 & \text{if $x$ is not rational}.
\end{cases}
$$
