Problem

Source: II International Festival of Young Mathematicians Sozopol 2011, Theme for 10-12 grade

Tags: number theory, permutations



Let $S$ be the set of all 9-digit natural numbers, which are written only with the digits 1, 2, and 3. Find all functions $f:S\rightarrow \{1,2,3\}$ which satisfy the following conditions: (1) $f(111111111)=1$, $f(222222222)=2$, $f(333333333)=3$, $f(122222222)=1$; (2) If $x,y\in S$ differ in each digit position, then $f(x)\neq f(y)$.