# Minimum number of swaps

This puzzle is related to this math question.

Consider $$4$$ lists of integers: $$(0,0,0,0,0,0,0,0)$$, $$(1,1,1,1,1,1,1,1)$$, $$(2,2,2,2,2,2,2,2)$$, $$(2,2,2,2,2,2,2,2)$$ where order does not matter.

We want to apply repeatedly some swaps, i.e. exchange an element of a list with an element of another list, till the absolute difference between the sums of the elements of any two lists is not greater than $$2$$.

I have counted $$9$$ swaps to get a possible valid configuration: $$(0,0,0,1,2,2,2,2)$$ (sum is $$9$$), $$(0,1,1,1,2,2,2,2)$$ (sum is $$11$$), $$(0,0,1,1,2,2,2,2)$$ (sum is $$10$$), $$(0,0,1,1,2,2,2,2)$$ (sum is $$10$$), with maximum difference $$11-9=2$$.

Is it possible to obtain any valid configuration in less than $$9$$ swaps?

So, we can swap a 1 and a 2 to fix the 1 list. Then we can swap five 2s into the 0 list -- two from the list we already swapped a 1 into and 3 from the other. This leaves us with sums 9, 10, 10, 11 in 6 total swaps. The lists are: $$(0, 0, 0, 2, 2, 2, 2, 2)$$; $$(1, 1, 1, 1, 1, 1, 1, 2)$$; $$(0, 0, 1, 2, 2, 2, 2, 2)$$; $$(0, 0, 0, 2, 2, 2, 2, 2)$$