TITLE: Space filling curve whose all level sets are finite (countable)
QUESTION [8 upvotes]: Is there a continuous surjective function $f:[0,1] \to [0,1]^2$ such that
every level set $f^{-1}(y)$ is a finite set? If the answer is no, what about if we replace the finiteness of level sets by "countable level sets"?

REPLY [14 votes]: Recall the definition of the Peano square-filling curve $f:[0,1]\to[0,1]^2$, which  is given in terms infinite ternary strings. If $a\in [0,1]$ has a base $3$ representation of the form $0,a_1a_2a_3\dots$, the point $f(a):=(b,c)$ has base $3$ digits resp. $$b_n:={\bf k}^{a_2+a_4+\dots a_{2n-2}}a_{2n-1}$$
$$c_n:={\bf k}^{a_1+a_3+\dots a_{2n-1}}a_{2n}$$
where ${\bf k}$ is the involutory bijection of the set $\{0,1,2\}$ into itself given by $i\mapsto2-i$ (and exponents denote iterated composition, which in this case only depends on the parity of the exponent, since ${\bf k}^2={\bf id}$).  As Peano observes, this gives a bijection (actually a homeomorphism wrto product topologies of discrete spaces) $\{0,1,2\}^{\mathbb{N}}  \to  \{0,1,2\}^{\mathbb{N}}\times \{0,1,2\}^{\mathbb{N}}$. In fact
$$a_{2n-1}:={\bf k}^{c_1+c_2+\dots +c_{n-1}}b_{n}$$
$$a_{2n}:={\bf k}^{b_1+b_2+\dots +b_{n}}c_{n}.$$
The point of the whole construction is that, thanks to  the effect of the map ${\bf k}$, the above bijection on ternary strings is compatible with the quotient map $\operatorname{val}:\{0,1,2\}^{\mathbb{N}}  \to[0,1]$, that takes a ternary string $(a_1,a_2,\dots)$ to its value as a ternary expansion of a real number, $\sum_{n=1}^\infty 3^{-n}a_n$. The latter map $\operatorname{val}$ is surjective but of course not injective, due to points in $[0,1]$ with double representations of "ternary rationals", that is points in the set $T:=\{ m/3^r: r\in\mathbb{N},\  0<m<3^r\}$. So passing to the quotient produces a (continuous, surjective, not injective) map  $f:[0,1]\to[0,1]^2$. 
Now, going back to the question: it is immediate by the construction, that $f^{-1}(y)$ is a single point iff  $y\in T^c\times T^c$; it has two elements if $y\in (T^c \times T)\cup (T\times T^c) $, and it has either two or four elements if  $y\in T\times T$. 
This is also mentioned in Peano original short paper.