This question is a bit of a corollary to this one: Generate a random permutation of the first $n$ numbers on the fly
I have some customers coming to my shop. I'll accept the first $n$ and then close the shop. I'll assign each customer an ID between $1$ and $n$. The customers know they're going to get an integer ID, but don't know what $n$ is. Before they're assigned their ID, they will be given a chance to guess it. If they get it right, they'll be given a $1\$$ discount on any purchase.
The customers are very smart and will maximize their chances of getting the discount. They also talk to each other and so know the previous ID's. I want to minimize the discount I end up shelling out.
It seems intuitive that the best strategy for assigning ID's is to do it in a random order. So, take the numbers $1$ to $n$ and put them in an array. Randomly permute that array using the Fisher Yates shuffle and assign the IDs based on successive indices of the array. If the customers knew what $n$ was, the first customer would guess anything from $1$ to $n$, the second one would rule out the ID of the first customer and so on, making the total discount I'd end up giving becoming on average:
$$d = \sum\limits_{i=1}^n\frac{1}{i}$$
But, what will $d$ become when they don't know $n$?
The total discount is just what you said given that the customers know $n$. Each customer should guess the smallest number not yet handed out. If $i$ numbers have been handed out and the rest are randomly ordered, the chance this number wins is $\frac 1{n-i}$. The discount you award is then $\sum_{i=1}^n \frac 1{n-i}=\sum_{i=1}^n\frac 1i=d$ because you are adding the same terms in the reverse order. The point is that each customer knows that his/her number is still in play. If the number is less than the highest given out, it is in play. If you have given out $1$ through $k$ and no more, $k+1$ must be in play because you have not closed up. The customer does not know the chance they will win because they don't know $n$, but they know this number is as good as they can do.