TITLE: Hat 'trick': Can one of them guess right?
QUESTION [29 upvotes]: There are $n$ boys and $n$ girls. Each of them is given a hat of only 4 possible (known) colors and doesn't know its color. Now each can only see all the colors of hats of those of the other gender and no contact is allowed, then each is asked to guess the color of their own hat at the same time. Determine whether such $n$ exists that there is a strategy that at least one child can guess right under any circumstances.
When there are only 3 possible colors, the problem has been solved ($n=2$ is OK) through simple algebra. But when it comes to 4 colors, the problem seems much harder. Please help.
Solution for 3 colors ($n=2$): we use 0, 1, 2 to represent the colors, the boys are $a, b$ and girls are $c, d$, respectively. Each boy knows the value of $c, d$, while each girl knows the value of $a, b$.
Now consider the four number:$$a+b+c,$$ $$d+a-b,$$ $$d+b-c,$$ $$d+c-a.$$ It's easy to show at least one of them is divisible by 3. As a result, the strategy is: $A, B, C, D$ guess $c+d$, $c-d$, $-a-b$, $b-a$$\pmod 3$ respectively, and one of them must be right.

REPLY [2 votes]: I worked out the intricated solution of @barto in the case of $k=4$, and it is too long for a comment.
So take 25 girls, set $N=\binom{25}{7}$, $I=\{1,\dots,N\}$ and $n=\binom N3$ and take $n$ boys. For $j=1,\dots, n$ (that is for each boy) take 
a set $U_j$ subset of $I$ with three elements. Let the set of colors be $C=\{a,b,c,d\}$ and set $C'=\{a,b,d\}$. For each $j$ fix a bijection
$\sigma_j: C'\to U_j$.
Moreover, for every $i=1,\dots,N$ choose some subset $G_i$ of $\{1,\dots,25\}$ of seven indices. The $G_i$, $U_j$ and $\sigma_j$ are known to everyone beforehand.
We also need to fix for each $j$ and the set $U_{j}=\{i_1,i_2,i_3\}$, three sets $T_1,T_2,T_3$, subsets of cardinality 4, of $G_{i_1}$, 
$G_{i_2}$ and $G_{i_3}$ respectively, such that $T_i\cap T_j$ is either empty or equal to $T_i$.
Now given $X\in C^{25}$ (any possibility of the colors of the girls) set 
$$i_0(X)=i_0=\min\{i: \# \{X_k, k\in G_i\}=1\}$$
Since there are four colors and 25 girls, necessarily there is a set of seven girls with the same color, and so $H=G_{i_0}$ is the one of these sets 
with the minimal index. All boys know the colors of the hats of the girls, so $H$ is known to the boys, and their decision can be codified by the following function
$B:C^{25}\to C^n$ given by
$$B(X)_j=\left\{ \begin{array}{ll} (\sigma_j)^{-1}(i_0(X))& \text{if }i_0(X)\in U_j\\ c &\text{if } i_0(X)\notin U_j\end{array}\right.$$
On the other hand the girls take the decision in two steps:
First, they determine one boy $j_0$ such that $i_0(X)$ is in $U_{j_0}=\{i_1,i_2,i_3\}$, if all the boys have the wrong answer. Since for the subsets of cardinality 4 $T_1,T_2,T_3$, of $G_{i_1}$, 
$G_{i_2}$ and $G_{i_3}$ respectively,  $T_i\cap T_j$ is either empty or equal to $T_i$, we obtain that for at least one of the sets $T_i$, all girls in that set  have the same color. So they choose their colors such that for each $T_i$ the four girls choose different colors (which are already determined previously for each $j_0$), and so at least one girl has the right answer.
${\bf Final Comments:}$
This is the strategy I understood from Barto's answer and comments. It remains to prove that the girls can choose a boy with $j_0$ such that $i_0(X)$ is in $U_{j_0}=\{i_1,i_2,i_3\}$, if all the boys have the wrong answer (It seems to me to be equivalent to the first lemma of barto).
In fact, if there is at least one boy with color $Y_j=c$, they set $j_0=\min\{j:\ Y_j=c\}$. Then, if the boy is wrong, necessarily  $i_0(X)\in U_{j_0}$,
by the definition of $B$. On the other hand, if no boy has color $c$, there is an inductive process (the girls should have a laptop to follow the process)
starting from the set $J=\{i=1,\dots,N\}$ (or, equivalently $J=\{G_i:\ i=1,\dots,N\}$) and eliminating one of the $i$'s (one of the $G_i$'s) 
at each step, such that at the end we are left with three indices and $i_0$ is one of them (with three sets $G_i$ and $H$ is one of them). 
Inductive step: If $\#J>3$, then take any subset of three elements, $\{i_1,i_2,i_3\}$. This subset is a $U_j$ for some $j$, and we eliminate the index
$\sigma_j(Y_j)\in U_j$. Note that since we assume that no boy has the color $c$, the index $\sigma_j(Y_j)$ is well defined.
It is impossible that $i_0(X)=\sigma_j(Y_j)\in U_j$: If $i_0(X)\notin U_j$, then this is clear, and if $i_0(X)$ is in $U_j$, since 
the boy is wrong,
$$
 \sigma_j(Y_j)\ne \sigma_j(B(X)_j)=i_0(X).
$$
So the inductive procedure yields a set of three indices such that one of them is $i_0$, necessarily it is a $U_j$, and we set $j_0=j$. 
Finally a comment on the number 7 for the cardinality of the $G_i$'s (opposed to 10 suggested by Barto). If you have three sets $G_1,G_2,G_3$ 
of 7 elements, then 
-if the intersection of the three sets has 4 or more elements, you can set $T_1=T_2=T_3$ a subset of 4 elements in the intersection. 
-if the intersection of two sets say $G_1, G_2$ has 4 or more elements but $G_1\cap G_2\cap G_3$ has less than four, you can set $T_1=T_2$ a subset of 4 elements in the intersection of $G_1$ and $G_2$ and $T_3$ a set in $G_3\setminus (G_1\cap G_2)$ of four elements.
-If no intersection of two sets has 4 or more elements, take $T_1$ in $G_1\setminus G_2$, $T_2$ in $G_2\setminus G_3$, $T_3$ in $G_3\setminus G_1$, of four elements respectively.