I've been working on a problem for my Algorithms class, but I've found myself stuck. The prompt is as follows.
You start with an empty room and a group of n people waiting outside. At each step, you may either admit one person into the room, or let one out. Please design an algorithm which generates a sequence of $2^n − 1$ steps, so that every possible combination of people is achieved exactly once. For example, for $n = 3$, one possible sequence would be
$\qquad\displaystyle e_1, e_2, x_1, e_3, e_1, x_2, x_1$.
where $e_i$ means person $i$ enters the room and $x_j$ means person $j$ exits the room
Hint: study the Hanoi Tower algorithm.
In my research on the prompt, I've found many people referencing Gray Code, but I don't understand how to implement it in an algorithm to compute this combination. I also found a very similar problem, but there wasn't an actual implementation of it.
It would be greatly appreciated if you could point me in the right direction on where to go with this algorithm.