I have a lock on my dorm door that's really stupid. Basically, it just checks whether or not the sequence of numbers I've put in is the combo, whether or not the lock was reset between guesses. So let's say my combo is 5556. Then I can input 555555556 into my lock and it'll unlock, without having to reset after inputting the first four numbers.
I tried to calculate the expected number of random number guesses to eventually input the right combo by assuming each "guess" was independent. For example, the input of 123454321 has 6 "guesses": 1234, 2345, 3454, 4543, 5432, 4321. Assuming this, the expected length of input required would be 10,000, for 10^4 permutations of a 4 digit combo.
However, to check my work, I created a simulation with a queue object and random number generators and ran 100 trials per experiment over 100 experiments in Python. In every experiment, the average was always above 10,000 by a significant margin, ranging from 500-2000.
I'm wondering, are the guesses really independent? What is the actual expected value?
You can approach this as a Markov process. You find that the state transition table depends on the structure of the correct solution. To take two extremes, if the solution is $1234$ then your states are
OTOH, if your solution is $1111$ then your states are
Clearly the expected length should be longer for the second case than for the first: in both cases you need four consecutive successes, but in the first case a failure from one sequence can be the first success in another sequence.
In light of the comment
here's how to do it without getting too convoluted. Take $1234$ as an example. Let $E_S$ denote the expected number of steps from suffix $S$ to the capturing suffix $1234$. The transitions convert directly into simultaneous equations $$\begin{eqnarray}E_\varepsilon &=& 1 + \frac{1}{10} E_1 + \frac{9}{10} E_\varepsilon \\ E_1 &=& 1 + \frac{1}{10} E_{12} + \frac{8}{10} E_\varepsilon + \frac{1}{10} E_1 \\ E_{12} &=& 1 + \frac{1}{10} E_{123} + \frac{8}{10} E_\varepsilon + \frac{1}{10} E_1 \\ E_{123} &=& 1 + \frac{1}{10} E_{1234} + \frac{8}{10} E_\varepsilon + \frac{1}{10} E_1 \\ E_{1234} &=& 0 \end{eqnarray}$$