Problem 74. Coins

You have 20 coins in front of you, half of which are heads and half are tails. You can flip any coin you want without seeing whether it is currently heads or tails. The goal is to divide the coins into two groups so that the number of heads in the two groups are the same. Can you do this?
What about the case that there are 21 coins and 5 of them are heads initially?
The answer to both cases are positive.
For the first case, we divide the coins into two groups of equal size (10 coins in each group). Let \(x\) be the number of coins in the first group that are heads. Since the total number of coins that are heads in the beginning is 10, we know that there are \(10-x\) coins in the second group that are heads. Notice that the size of the second group is also 10 and thus there are \(x\) coins in the second group that are tails. Therefore, by flipping all coins of the second group we would have the same number of heads in both groups.
The second case is much like the first case. This time, we divide the coins into two groups of size 16 and 5. Let \(x\) be the number of heads in the first group (of size 16). Since the total number of heads is equal to \(5\), this means that we have \(5-x\) heads in the second group (size 5). Also, notice that the size of the second group is also 5 and therefore there are exactly \(x\) tails in the second group. Therefore, by flipping all coins of the second group we would have the same number of heads in both groups.