How long will it take to solve this permutation puzzle? Let's say I'm designing a simple puzzle. There are n panels, each numbered 1:n. I randomly select a permutation of panels of n length (the password). Your goal is to guess the password with no other information. The panels follow these rules:


*

*If you correctly select the next number in the password, the panel turns on

*If you select an incorrect number, all the panels turn off and the sequence resets


This means that if you correctly guess the first two digits, those panels will light up. However, if you press the wrong panel for the third digit, then the first two panels turn off. You'll have to go back and press them again before trying a different guess for the third digit.
Let's look at an example. Let's say there are n=4 panels, and the randomly selected password is 2341. You might go about guessing the password like this:


*

*1s: Press panel 1: Nothing happens

*2s: Press panel 2: Panel 2 lights up

*3s: Press panel 1: All panels turn off

*4s: Press panel 2: Panel 2 lights up

*5s: Press panel 3: Panel 3 lights up

*6s: Press panel 1: All panels turn off

*7s Press panel 2: Panel 2 lights up

*8s Press panel 3: Panel 3 lights up

*9s: Press panel 4: Panel 4 lights up

*10s: Press panel 1: Panel 1 lights up


In this example, it took you ten seconds to solve the puzzle.
On average, how long will it take to guess a password of length n? An R function that correctly calculates the answer would be an acceptable answer if it can't be expressed in a formula (or if the function is simpler).
To help test answers, we have these known values:


*

*n=1 takes 1 second

*n=2 takes 2.5 seconds

*n=3 takes 5 seconds

*n=4 takes 9 seconds


I calculated that by manually writing down every possible event and manually averaging them. For example, if we look at n=3, each of the following has a 1/6 chance of happening:
Format: [Time to guess]: [Time on first digit],[Time on second digit],[Time on third digit]


*

*3s: 1,1,1

*5s: 1,3,1

*4s: 2,1,1

*6s: 2,3,1

*5s: 3,1,1

*7s: 3,3,1


That averages to 5 seconds. 
 A: If there are $n$ digits in the password and you know the first $k$ of them, on average the next one will take $\frac {n-k+1}2$ tries.  The first try takes just $1$ second because you have the previous ones lit up, then the rest take $k+1$ seconds. Adding these we get
$$\sum_{k=0}^{n-1}\frac {(n-k+1)(k+1)}2-k
=\sum_{k=0}^{n-1}\frac {n+1+(n-2)k-k^2}2\\
=\frac 1{12}n(n^2+11)$$
A: To get the first digit, it will take you on average $\sum\limits_{k=1}^n \frac{k}{n}$.
To get the second digit, it is a little trickier. If you get it at the first attempt, then it took only an extra press to get the second digit. But if that is incorrect, you need to press the first digit, and then de next second digit, so you have to press three panels, and so on. 
To get the third digit, if you get it at your first try, it takes only one extra push. But if you don't get it, you have to press $3$ panels before trying the next panel. 
The probability of being successful at your $k$ attempt finding the $i+1$ number is going to be $\frac{1}{n-i}$, and it will take you $(i+1)(k-1) + 1$ presses to get there. For each wrong panel before, you pressed it, and then had to press $i$ of the correct panels. 
Then, the expected amount of time it is going to take you to get the $i+1$ number is going to be $\sum\limits_{k=1}^{n-i} \frac{(k-1)(i+1)+1}{n-i}$. 
To get the expectation we are looking for, just add up that quantity
$\mathbb{E}\left[T\right] = \sum\limits_{i=0}^{n-1}\sum\limits_{k=1}^{n-i} \frac{(k-1)(i+1)+1}{n-i}$.
You can compute the sum from there. 
