A question related to continuous functions in general topology. 
Q. Let $X=\{0,1,2\}$ and the topology on $X$: $\mathcal T=\{\varnothing,X,\{0\},\{0,1\}\}$. A continuous function $f:X\to X$ is such that $f(1)=0$ and $f(2)=1.$ Find $f(0).$

My work: Since $f$ is continuous, it must be continuous at each point in $X.$ That is, $f$ is continuous at $0\in X$ as well.
If possible, let $f(0)=2.$ As $2\in X$ and $X$ is an $\mathcal T$-open subset in $X,$ codomain of $f.$ So in this case, $X$ is a nbd of $f(0).$
Now, $f^{-1}(X)=X$ which is an open subset of $X$ (domain). We also have $0\in X$ i.e., $X$ is a nbd of $0.$ Thus, we find that: if we let $f(0)=2,$ then the inverse image of nbd of $f(0)$ becomes a nbd of $0$ and hence $f$ becomes continuous at the point $0\in X,$ as desired, and so indeed $f(0)=2$ is the right choice. (Also, $f$ being a function there exists no other value of $f(0).$)
I don't know the answer to this question. So, just to be sure, I want to know whether I am correct or not. Also, if I am correct, is there any other approach to get the same result without making the assumption $f(0)=2$ at the beginning?
 A: The correct answer is actually that $f(0) = 0$.
The general definition of continuity is that $f : A \to B$ is continuous iff for all open sets $U \subseteq B$, $f^{-1}(U) \subseteq A$ is open.
In this case, note that $\{0\}$ is open, and thus $U := f^{-1}(\{0\})$ is open. Note that $1 \in U$. Also note that for all open $V \subseteq X$, if $1 \in V$ then $0 \in V$. This can be proved by examining each open set one by one.
Therefore, $0 \in U$. Then $0 \in f^{-1}(\{0\})$. Then $f(0) = 0$.
Edit: I think I'm starting to see where the confusion lies. Let me solve an analogous problem.
Consider $a \neq b \neq c \neq a$. Define $Y = \{a, b, c\}$. Define $\mathcal{T}_Y = \{\emptyset, \{a\}, \{a, b\}, \{a, b, c\}\}$.
Suppose we're given a continuous function $Y \to X$ such that $f(c) = 1$ and $f(b) = 0$. What is $f(a)$?
The answer is that $f(a) = 0$. To see this, consider the fact that $\{0\}$ is an open set in $X$. Therefore, since $f$ is continuous, $f^{-1}(\{0\})$ must be an open set in $Y$. Let $U = f^{-1}(\{0\})$.
We know that $f(b) = 0$. Therefore, $f(b) \in \{0\}$. Therefore, $b \in f^{-1}(\{0\}) = U$.
Let's look at all the possible values of $U$. Since $b \in U$, that means that either $U = \{a, b\}$ or $U = \{a, b, c\}$. Either way, we see that it must be the case that $a \in U$.
Since $a \in U = f^{-1}(\{0\})$, we see that $f(a) \in \{0\}$. Therefore, $f(a) = 0$.
Now that we've established that $f(a) = 0$, just take $a = 0$, $b = 1$, and $c = 2$. Then $Y = X$ and $\tau_Y = \tau$. So we see that $f(0) = 0$.
