Problem. The Chinese rings (Baguenaudier): rings on a bar. Ring can always be moved on or off; ring can be moved iff ring is on and rings are off. Remove all rings.
Answer: moves: The sequence of states visited is the reflected Gray code.
long long chineseRingsMoves(int n) { return (1LL << (n + 1)) / 3; } // minimum moves to remove all n ringsProof: the move count
Let be the minimum moves to remove rings. To remove ring , rings must be off and ring on: remove the first rings (), move ring (1), put the first back (, by reversibility), then remove the first rings (). So with , . The closed form satisfies the same recurrence and initial values (check alternates between and ). The states form a path in which each move flips one ring, exactly the reflected Gray code sequence (Gray Code). Checked by BFS over all states for .