Snoopy then wondered, if he had n coins, was there a minimum number
x such that he could do exactly x flips to satisfy his requirements?
Find the number x when it exists and prove that your answer is
correct.
Hint: For some n there are no solutions.
There can be no solution in the case when the number of coins is even.
If the number of coins is odd, either the number of heads or the number of tails must be even. If the even number is zero, keep flipping the same coin n-1 times. Otherwise the strategy is to identify coins with an even number of same faces (say those showing heads) and keep flipping them until they all turn tails and we have used n-1 flips. Of course there are at most n-1 heads so this is sufficient. If the even number is less than n-1 we keep flipping a tail until we have used all n-1 flips.
Proof of correctness: The proof uses a parity argument.
First note that we need an odd number of flips to change parity of the number of heads or tails. That is if we flip heads to tails an odd number of times the parity of the number of heads changes. On the other hand an even number of slips preserves parity.
Therefore if there are an even number of coins, the number of heads and tails have the same parity. If this parity is even, we need an even number of flips to change them to all heads or all tails and if the parity is odd, we need an odd number of flips to change them to all heads or all tails. Therefore there can be no solution in the case when the number of coins is even.
If the number of coins is odd, then the the number of heads and tails have opposite parity. Thus a solution is possible.
If one thinks about the problem one realizes that using an even number of flips always works (odd number of flips fail when all coins already show heads or all show tails). In fact the number must be n-1 to handle the case 1 is heads and n-1 tails or vice versa. In general this works because one applies n-1 flips to coins showing heads (respectively tails) initially if there are an even number of heads (respectively tails) initially. Even if there are less than n-1 heads the number is even and even number of flips can preserve parity.