This is a dynamic programming problem.
For a roll, the expectation will be 3.5.
For two rolls, if your first roll gets 1 or 2 or 3, you will roll it again. In other words, you have 1/2 chance to do the second roll and get the expectation as 3.5. If 4 or 5 or 6, you will stop here since it is good enough above the expectation (3.5). For such outcome as 4 or 5 or 6, your average is 5 with another 1/2 chance. So the total expectation will be 1/2*3.5 + 1/2*5 = 4.25.
For three rolls, you will consider the case differently after the first rolls. If I obtain 5 or 6, I will stop here for just one roll since it achieve above my expectation. Otherwise, I will roll twice and obtain the expectation of two rolls as 4.25. In total, the expectation will be 2/3*4.25 + 1/3*5.5 = 14/3 = 4.67.
Suppose that we have k rolls and obtain the expectation $E$ above 5, we have to change the strategy again after the first roll. You can stop rolling if you get 6, otherwise keep going to obtain $E$ values. The new expectation will be like that:
$$E_{new} = 1/6*6 + 5/6*E_{old} $$
For n rolls, write a program in Python as the following:
def die_fair_value(rolls):
cnt=1
val=3.5
while cnt < rolls:
if val < 4:
val = 1/2.0*5 + 1/2.0*val
elif val<5:
val = 1/3.0*5.5 + 2/3.0*val
else:
val = 1/6.0*6 + 5/6.0*val
cnt += 1
return val