TITLE: Changing combination lock
QUESTION [8 upvotes]: Suppose you have a combination lock (n digits, m symbols) that is unlocked by one specific n-digit key sequence. However, trying a wrong key changes it according to an fixed but unknown function: new key = f(current key, wrong key). Is there an algorithm (deterministic or not) which can surely find the key in finite time?
Also, does this problem has a name?

REPLY [5 votes]: Let $N=m^n$, the number of possible keys. I will use usul's idea in a comment to show that it can be solved in at most $N^3\log N$ guesses.
Make a variable $s[F,s_0]$ for each possible function $F$ and state $s_0$.  The number of variables is initially $N^{1+N^2}$. The value of $s[F,s_0]$ is a state, initially $s_0$, and in general it equals the state we would be in now if the function is $F$, the initial state was $s_0$, and we made the guesses we have made so far.  Variables can be erased as we work.
Now we start guessing, but we do it greedily.  Namely, at each step we try a state $s$ that is the most common value of the remaining variables.  If it works, we are done.  If it doesn't work, we can erase all the variables which have value $s$ and update all the others.  At each step this eliminates at least the fraction $1/N$ of the variables.  So we are definitely finished after $K$ guesses if $ N^{1+N^2} (1-1/N)^K \lt 1$.  This holds when $K = N^3\log N$.