In a row of $40$ kids, $22$ are sitting next to girls and $30$ are sitting next to boys. How many girls are there? 
There are $40$ kids sitting in a row.  Number of kids sitting next to girls is 22, Number of kids sitting next to boys is 30. How many girls are sitting in a row?

This is a problem from my brother's 6th grade homework. I've tried to solve it by considering easier cases and going from there, but couldn't really see the general pattern. Is there an easy solution that a 6th grader can understand?
 A: If they were sitting in a circle there would be a "simple" (though in fact requiring a very sophisticated level of thinking) solution, as follows.

There are $22$ kids sitting next to girls and $30$ sitting next to boys. Therefore  there are $22+30-40=12$ sitting next to girls and boys, $10$ sitting next to only girls and $18$ sitting next to only boys.
Now let everyone hold hands in the circle. $12$ people are holding one girl's hand and $10$ are holding two girls' hands. Therefore there are $12+2\times10=32$ girls' hands, and so $16$ girls in total.

Unfortunately having a row, rather than a circle, breaks this argument, since there are two people only using one hand, and they could be boys or girls, and they could be next to boys or girls (messing up the counting in two ways). I don't see a good reason why there is a unique answer in this case.
A: Divide the kids into three categories: $g$ kids not sitting next to any boy, $b$ kids not sitting next to any girl, and $n$ kids sitting next to both. It’s not hard to determine that $n=12$ and hence that $g=10$ and $b=18$. Now imagine that we wrap the row around into a circle, so that the kids on the two ends are now sitting next to each other; what are the possible changes in $g,b$, and $n$?
An end child who was sitting next to a girl can now be between two girls or between a girl and a boy; the first possibility does not change any of the quantities, and the second decreases $g$ by $1$ and increases $n$ by $1$. Similarly, an end child who was sitting next to a boy can now be between two boys or between a girl and a boy, the first possibility resulting in no change and the second in an increase of $n$ by $1$ at the expense of $b$. The following possibilities therefore exist:

*

*no change in $g,b$, and $n$ (e.g., a row of the form $GG\ldots GG$);

*$n$ increased by $1$ at the expense of $g$ (e.g., a row of the form $BG\ldots GG$);

*$n$ increased by $1$ at the expense of $b$ (e.g., a row of the form $GB\ldots BB$);

*$n$ increased by $2$ at the expense of $g$ (e.g., a row of the form $BG\ldots GB$);

*$n$ increased by $2$ at the expense of $b$ (e.g., a row of the form $GB\ldots BG$); and

*$n$ increased by $2$ and each of $g$ and $b$ decreased by $1$ (e.g., a row of the form $BB\ldots GG$);

In short, after we close the circle the possible values of the triple $\langle g,b,n\rangle$ are $\langle 10,18,12\rangle$, $\langle 9,18,13\rangle$, $\langle 10,17,13\rangle$, $\langle 8,18,14\rangle$, $\langle 10,16,14\rangle$, and $\langle 9,17,14\rangle$.
As in Especially Lime’s answer we now have the kids hold hands around the circle; $g$ kids are each holding two girls’s hands, and $n$ are each holding one girl’s hand for a total of $2g+n$ hands and therefore $g+\frac{n}2$ girls in the row. In particular, $n$ must be even, so we can rule out the second and third possibilities above. The remaining four yield $16,15,17$, and $16$ for the number of girls, so unless some of them can be ruled out by consideration of the internal structure of the row of kids, the question does not have a unique answer.
A: 
No, I'm sorry for the ambiguity (I translated this problem). If there's at least one girl sitting next to me, that means that i'm sitting next to a girl. That's what's meant.

This comment from OP seems to change the interpretation of the question a little with 'at least' being included - it would read more like:

There are 40 kids sitting in a row. The number of kids sitting next to at least one girl is 22, and the number of kids sitting next to at least one boy is 30. How many girls are sitting in a row?

It'd also be good to confirm whether the final question is referring to the number of girls sitting in 'a row', as in directly next to other girls, or in the row entirely
This seems like an easier problem to solve - we now have four pieces of information:

*

*22 kids are sitting next to at least one girl

*18 kids are not sitting next to any girls

*30 kids are sitting next to at least one boy

*10 kids are not sitting next to any boys

Let's build a 'row' with 40 slots using b for Boys, g for Girls, and X for not yet filled:

{X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X}

Start with the groups of kids who are only sitting next to kids of the same gender - 18 boys not next to any girls, and 10 girls not next to any boys. Put those groups at either end of the row:

{b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,X,X,X,X,X,X,X,X,X,X,X,X,g,g,g,g,g,g,g,g,g,g}

For those people to definitely fit into the 'only sits with same gender' groups, you need an extra 'buffer' boy and girl at the end of each of those groups:

{b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,X,X,X,X,X,X,X,X,X,X,g,g,g,g,g,g,g,g,g,g,g}

This satisfies conditions 2 and 4, so we need to address conditions 1 and 3. With the kids already placed, we have 11 kids who are sitting next to at least one girl (all of the girls), and 19 kids who are sitting next to at least one boy (all of the boys). We need another 22 - 11 = 11 kids sitting next to at least one girl, and 30 - 19 = 11 kids sitting next to at least one boy.
We have 10 empty slots still to fill. By filling these with alternating boys and girls we add an extra 10 kids to each category, and we also convert each of the two 'buffer' kids from earlier to be sitting next to one of each gender.

{b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,g,b,g,b,g,b,g,b,g,b,g,g,g,g,g,g,g,g,g,g,g}

This satisfies all 4 conditions, and gives us a total of 16 girls in the entire row, or 11 girls sitting in a row.
Feel free to edit with an actual proof, this was really just a simple step-by-step 'trial and error' style solution, using my first assumption at each step, that turned out to work - but I'd assume that that's probably what was expected for a sixth-grade student.
A: The simplest (for a 6-th grade ?) didactical approach I can think of would develop
through the following stages.
Here I am summarizing them in "adult" terms.
a) Consider the following four building blocks and associated table
$$
\matrix{
   {K_{\,n,\,0}  = B_{\,n}  = \left( {B,B, \ldots ,B} \right)} & {K_{\,0,\,n}  = G_{\,n}
  = \overline {K_{\,n,\,0} }  = \left( {G,G, \ldots ,G} \right)}  \cr 
   {\left[ {\matrix{
   {Kids\,near\;Girls} & 0  \cr 
   {Kids\,near\;Boys} & n  \cr 
   {Boys} & n  \cr 
   {Girls} & 0  \cr 
 } } \right]} & {\left[ {\matrix{
   {Kids\,near\;Girls} & n  \cr 
   {Kids\,near\;Boys} & 0  \cr 
   {Boys} & 0  \cr 
   {Girls} & n  \cr 
 } } \right]}  \cr 
   {} & {}  \cr 
   {K_{\,n - 1,\,1}  = \left( {B, \ldots ,B,G} \right)} & {K_{\,1,\,n - 1}  = \overline {K_{\,n - 1,\,1} }
  = \left( {B,G, \ldots ,G} \right)}  \cr 
   {\left[ {\matrix{
   {Kids\,near\;Girls} & 1  \cr 
   {Kids\,near\;Boys} & n  \cr 
   {Boys} & {n - 1}  \cr 
   {Girls} & 1  \cr 
 } } \right]} & {\left[ {\matrix{
   {Kids\,near\;Girls} & n  \cr 
   {Kids\,near\;Boys} & 1  \cr 
   {Boys} & 1  \cr 
   {Girls} & {n - 1}  \cr 
 } } \right]}  \cr 
 } 
$$

*

*make clear that joining such blocks any row sequence of boys/ girls can be composed,

*explore the  rules of composition of the joint table from the starting ones;

*emphasize how for instance the number of kids sitting near to girls  pass from a minimum of $g$ (the number of girls),
to $2g$ (couples $(GB)$) and up to the maximum $3g$ (triples $(BGB)$) and correspondent number of boys, etc. ;

*explore the  inverse rules for decomposing a table;

b) Move down to consider just the elementary blocks $B$ and $G$, and repeat the above
exploring about table composition for a sequence $B^{m_1},\,  G^{n_1}, \, B^{m_2}, \; \cdots$
$$
\eqalign{
  & \matrix{   {B^{\,m_{\,1} } }  \cr 
   {\left[ {\matrix{ {Kg} & 0  \cr {Kb} & {m_{\,1} }  \cr B & {m_{\,1} }  \cr G & 0  \cr  {E = Kg + Kb - B - G} & 0  \cr 
 } } \right]}  \cr 
 } \matrix{
   {G^{\,n_{\,1} } }  \cr 
   {\left[ {\matrix{{Kg} & {n_{\,1} }  \cr {Kb} & 0  \cr B & 0  \cr G & {n_{\,1} }  \cr  E & 0  \cr 
 } } \right]}  \cr 
 }  \Rightarrow \matrix{   {B^{\,m_{\,1} } G^{\,n_{\,1} } }  \cr 
   {\left[ {\matrix{{Kg} & {n_{\,1}  + 1}  \cr {Kb} & {m_{\,1}  + 1}  \cr B & {m_{\,1} }  \cr G & {n_{\,1} }  \cr 
   E & 2  \cr  } } \right]}  \cr 
 }  \Rightarrow   \cr 
  &  \Rightarrow \matrix{
   {B^{\,m_{\,1} } G^{\,n_{\,1} } B^{\,m_{\,2} } }  \cr 
   {\left[ {\matrix{ {Kg} & {n_{\,1}  + 2}  \cr {Kb} & {m_{\,1}  + m_{\,2}  + 1 + \left[ {2 \le n_{\,1} } \right]}  \cr 
   B & {m_{\,1}  + m_{\,2} }  \cr  G & {n_{\,1} }  \cr  E & {3 + \left[ {2 \le n_{\,1} } \right]}  \cr 
 } } \right]}  \cr 
 }  \Rightarrow \matrix{
   {G^{\,1} B^{\,m_{\,1} } G^{\,1} }  \cr 
   {\left[ {\matrix{   {Kg} & {1 + \left[ {2 \le m_{\,1} } \right]}  \cr   {Kb} & {m_{\,1}  + 2}  \cr 
   B & {m_{\,1} }  \cr    G & 2  \cr    E & {1 + \left[ {2 \le m_{\,1} } \right]}  \cr 
 } } \right]}  \cr  }  \Rightarrow   \cr 
  & \matrix{
   {B^{\,m_{\,1} } G^{\,n_{\,1} } B^{\,m_{\,2} } G^{\,n_{\,2} } }  \cr 
   { \Rightarrow \left[ {\matrix{   {Kg} & {n_{\,1}  + \,n_{\,2}  + 2 + \left[ {2 \le m_{\,2} } \right]}  \cr 
   {Kb} & {m_{\,1}  + m_{\,2}  + 2 + \left[ {2 \le n_{\,1} } \right]}  \cr 
   B & {m_{\,1}  + m_{\,2} }  \cr    G & {n_{\,1}  + \,n_{\,2} }  \cr 
   E & {4 + \left[ {2 \le n_{\,1} } \right] + \left[ {2 \le m_{\,2} } \right]}  \cr 
 } } \right]}  \cr 
 }  \cr} 
$$
where $[P]$ denotes the Iverson bracket
c)With the building blocks above we should reach to be able to solve the problem at hand.
A: Hint: consider the case when the $\text{Number of girls} = \text{Number of boys}$, and they are aligned like this:
$G_{1}, B_{1}, G_{2}, B_{2}, ..., G_{19}, B_{19}, G_{20}, B_{20}$
We need to keep track of 4 properties:

*

*$\text{Number of girls: } 20$

*$\text{Number of boys: } 20$

*$\text{Kids sitting next to girls: } 20$

*$\text{Kids sitting next to boys: } 20$
the latter 2 comes from the fact that each kid has the same type of neighbour.
As $\text{Kids sitting next to girls}$ and $\text{Kids sitting next to boys}$ are not per specified, we need to change $\text{Number of girls}$ and/or $\text{Number of boys}$ by replacing one with the other. We need to know, when we do this replacement, how it changes the above 4 properties if

*

*the kid is at the end of the row

*the kid is not at the end of the row

These can be written up with formulas, and then we can calculate which and how many replacements lead to the specification.
