A safe is protected by a four-digit $(0-9)$ combination. The safe only considers the last four digits entered when deciding whether an input matches the passcode.
For instance, if I enter the stream $012345$, I am trying each of the combinations $0123$, $1234$, and $2345$.
Clearly, a 40000-length string $000000010002...9999$ is guaranteed to crack the safe.
Can we try each of the 10000 combinations using a shorter string? What's the shortest string we can devise to try every combination?
The object you are interested in is called a De Bruijn graph. Construct a graph where each node is one 4-digit sequence. Then put a directed edge from $a$ to $b$ if the last $3$ digits of $a$ are the same as the first $3$ digits of $b$.
See: http://en.wikipedia.org/wiki/De_Bruijn_graph
A directed Hamiltonian path will tell you what sequence to enter the digits (to try all possible combinations as fast as possible). These graphs always have such a path. So then, the fewest times you would have to push the button is $4$ (for the first code) and then $1$ more button push for each remaining possibility for a total of $1(4)+9999(1)=10003$ button pushes.