This is the problem on USAMTS:
A teacher plays the game “Duck-Goose-Goose” with his class. The game is played as follows: All the students stand in a circle and the teacher walks around the circle. As he passes each student, he taps the student on the head and declares her a ‘duck’ or a ‘goose’. Any student named a ‘goose’ leaves the circle immediately. Starting with the first student, the teacher tags students in the pattern: duck, goose, goose, duck, goose, goose, etc., and continues around the circle (re-tagging some former ducks as geese) until only one student remains. This remaining student is the winner. For instance, if there are $8$ students, the game proceeds as follows: student $1$ (duck), student $2$ (goose), student $3$ (goose), student $4$ (duck), student $5$ (goose), student $6$ (goose), student $7$ (duck), student $8$ (goose), student $1$ (goose), student $4$ (duck), student $7$ (goose) and student $4$ is the winner. Find, with proof, all values of $n$ with $n > 2$ such that if the circle starts with $n$ students, then the $n$ th student is the winner.
I've seen the case for $n=2$ in a Numberphile video which if expressed in base $2,$ just take the first digit and put it on the bottom, also called the Josephus problem.
How can I apply the same logic here?
Currently, I figured out that $3^n$ has position $1$ win every time, so I suspect the pattern still holds, but I can't prove it.
In the first passing around the circle, student $i$ $(i$ ranging from $1$ to $n)$, will be excluded if and only if $i \equiv 0$ or $i\equiv 2\pmod 3$. In other words, for the $n$-th student to avoid exclusion, we must have $n\equiv 1 \pmod 3$.
Suppose hence that $n = 3k+1$. After tagging each student exactly once, we're down to a circle with $k+1$ students, so if $k=0$, the game ends right after this first pass.
Suppose hence that $k>0$, so the game will continue. In this case, the $n$-th student is now the $(k+1)$-th.
Now, the teacher's pattern begins with Goose-Goose-Duck. This means that if $k+1\leqslant 3$, the $n$-th student will survive as a result of all others being tagged Goose before him.
If $k+1>3$, then we'll do a full pass around the circle. It follows that student $i$ $(i$ ranging from $1$ to $k+1)$ will be excluded if and only if $i \equiv 1$ or $i\equiv 2\pmod 3$. Hence, in order for the $(k+1)$-th student to avoid exclusion, we must have $k+1 \equiv 0 \iff$ $k \equiv2 \pmod 3$.
Suppose hence that $k = 3j+2$, so we had $3j+3$ students. Remember that to reach this point, we had to assume $k+1>3$, so necessarily $j>0$.
We're now reduced to $j+1$ students and the $n$-th student is now the $(j+1)$-th.
The pattern once again beings with Goose-Goose-Duck, so this goes on exactly like before: either $j+1\leqslant 3$ and the $n$-th students survives from others begin tagged Goose before him; or else we must have $j\equiv 2 \pmod 3$ in order for $n$ to avoid exclusion.
Of course, this pattern will repeat.
Our possible $n$ hence are
and if we continue in this fashion we'll now have to add $27=3^3$ to $25$ obtaining $n=52$, and then $52+27 = 79$. Proceeding we'll have $79 + 3^4 = 160$ and then $160 + 81 = 241$, and so on and so forth.
A compact way to consider the possible values of $n$ is hence to consider the infinite sum
\begin{align} \begin{array}{}&1&+&3&+&3&+&9&+&9&+&27&+&27&+&81&+&81&+&\dots\\ =&3^0&+&3^1&+&3^1&+&3^2&+&3^2&+&3^3&+&3^3&+&3^4&+&3^4&+&\dots\end{array} \end{align}
Any $n$ can be obtained from this infinite sum by truncating it. This does suggest a perhaps more formal representation in terms of ternary base representation:
$$n = \sum_{i=0}^k\,a_i\,3^i,$$
where $k\geqslant 0$ and $a_0 = 1$, $a_j = 2$ for all $0<j<k$ and $a_k \in \{1,2\}$.