Maximum work obtained by mixing 2 gases 
Two boxes containing the same number of moles of two ideal identical
  gases with the same adiabatic index (this is given as $\gamma$), at
  the same initial temperature $T_i$ but with different volumes, $V_1$
  and $V_2$, are brought together. Find the maximum mechanical work that
  can be obtained.

If the gases have all the parameters identical but the volumes, that means that they also have different pressures, so when we are mixing them, the gas with the higher pressure will do work on the gas with lower pressure. However, I have no idea how to calculate this work and the answer given is a big messy expression. 
It doesn't say anything about the recipients being adiabatically isolated, but I guess I have to assume that? The temperature will be constant? I think I should calculate the variation of entropy for the system and then relate this to the first principle to get the work done, but I have no idea how to do that.
 A: The entropy of $N$ molecules of an ideal gas in a volume $V$ at temperature $T$ can be expressed as:
$$S(N, V, T) = N k\log\left(\frac{V}{V_0}\right) + C_v\log\left(\frac{T}{T_0}\right) + S(N, V_0,T_0)$$
Here $V_0$ and $T_0$ define arbitrary standard conditions at which the entropy is known, and $C_v$ is the total heat capacity at constant volume. To derive this formula, you can consider the change in entropy from the standard conditions to the final state using an isothermal process at constant pressure where heat is added to the system, thus yields the first term. After that we can change the temperature from $T_0$ to $T$ by adding heat to the system at constant volume, the entropy change due to that process is given by the second term.
The initial entropy of the system can thus be expressed as:
$$S_{\text{initial}} = S(N,V_1,T_i) + S(N,V_2,T_i) =  N k\log\left(\frac{V_1V_2}{V_0^2}\right) + 2C_v\log\left(\frac{T_i}{T_0}\right) + K$$
where $K$ is a constant (for problems where the total number of molecules in the system does not change). The final state will be a state where the molecules are (or can be considered to be) in a volume of $V_1 + V_2$ at some temperature $T_f$. If no work can be extracted anymore the gases in the two boxes must be in thermal equilibrium with each other and then doesn't matter whether or not there is a separation between the gases. The final entropy is thus given by:
$$S_{\text{final}} = S(2N,V_1+V_2,T_f) =  2N k\log\left(\frac{V_1+V_2}{V_0}\right) + 2C_v\log\left(\frac{T_f}{T_0}\right) + K$$
Then for any process involving only the two boxes, $S_{\text{final}}\geq S_{\text{initial}}$.  The maximum amount of work we can extract from the system is obtain in the reversible case where the entropy stays the same. We can see this by considering two processes, one where the entropy increases and one where it stays the same. Then we can go from the latter to the former by dumping energy extracted in the form of work as heat into the system at constant volume of $V_1+V_2$ until we reach the same entropy as the former system (and as a result also the final temperature of the latter system, as volume, entropy and number of molecules completely determine the thermodynamic state of the system). Since we've then thrown away work to arrive at the former end state, with entropy increase you're alway worse off then when the entropy stays the same.
To find the maximum amount of work, we thus need to equate $S_{\text{final}}$ to $S_{\text{initial}}$, we can then solve for $T_{f}$, the drop in the internal energy is then the maximum amount of work extracted from the system (note that no heat can have been added or extracted from the system, because the total entropy has stayed the same, therefore the entire internal energy change is due to work). Solving for $T_f$ yields:
$$T_f = T_i \left(\sqrt{\frac{V_2}{V_1}}+\sqrt{\frac{V_1}{V_2}}\right)^{-\frac{N k}{C_v}} = T_i \left(\sqrt{\frac{V_2}{V_1}}+\sqrt{\frac{V_1}{V_2}}\right)^{1-\gamma}$$
where we've used that $C_V = \dfrac{f}{2}N k$ and $\gamma = \dfrac{f+2}{f}$ where $f$ is the effective number of degrees of freedom per molecule.
The total amount of work $W$ that can be extracted is therefore equal to:
$$W = 2 C_V (T_i - T_f) = \frac{2N kT_i}{\gamma - 1}\left[1-\left(\sqrt{\frac{V_2}{V_1}}+\sqrt{\frac{V_1}{V_2}}\right)^{1-\gamma}\right] $$
A: You have this doped out pretty well.  To get the maximum work out of it, you can manually hold an adiabatic partition between them and allow the gases to move the partition very gradually until the pressures equalize.  The work that the partition transmits to your hand will be the maximum work.  This is the same as the net work if each gas changes volume adiabatically and reversibly until each reaches a final pressure that matches that of the other.  So first express the pressure as a function of the volume of each and set the final pressures equal.  This will tell you the final volume of each, the final pressure, and the final state.  Then you can calculate the work done by each, and then the net work.
