Problem 5
people are seated in a circle. A total of coins are distributed among them, not necessarily equally. A move transfers one coin between two adjacent people. Find an algorithm using the minimum number of moves that leaves everyone with the same number of coins.
Step 5 of 5: Compare the wraparound move and iterate
Detailed analysis
Repeat the decreasing move until if no wraparound move is better. Also compute the change in for transfers across edge in both directions; if either decreases by more than one, use the direction with the larger decrease. Every move is legal and strictly decreases, so the process terminates at equal holdings and is minimal by the potential argument.