@Xazy,
Divide the coins into two piles A and B with x coins in A.
If there are p heads in A then there are x-p tails in A
But there are x-p heads in B, so turn all of A over so that its tails become heads, giving x-p heads as in B.
Remember x is just the
starting number of heads.
Example: Suppose x=10, p=3
A=(3H,7T) B=(7H, 33T).Turn A over giving new A=(7H,3T)