Today's dishwashers are better than those of yesteryear. In particular, a dishwasher made in year i costs Mi to buy and Ui to use each year, and these costs fall at a rate R

$$M_i = M_0 * R^i$$ $$U_i = U_0 * R^i$$ $$0 < R < 1$$

Assume I'll never die, dishwashers never fail, and that throwing away a dishwasher is free. What upgrade policy minimizes my cost of dishwashing?

I've so far considered policies that call for regular upgrades every y years. (Is the optimal policy of this type?) I reasoned that y is best when the cost of dishwashing over a period P is the same when y = P as when y = P - 1. This led to the following equation

$$M_0 + (y + 1)U_0 = M_0 + yU_0 + \frac{R^yM_0}{y} + R^yU_0$$

which simplifies to

$$R^y * \frac{M_0 + yU_0}{y} = U_0$$

I also wrote a program to brute force the problem for positive integers. On eight test cases the rounded positive solutions for y in the above equation do not agree with the solutions obtained by brute force. However they do agree when scaled by a factor of 1.4 before rounding.

The problem is invariant to M0 and U0 when their ratio is constant. And we can use time units other than years by adjusting U0 and R. Both the equation and the program seem to work as expected here.

Is my analysis wrong? Is the factor of 1.4 meaningful?

• On eight test cases, the expression in user436560's answer always had a clear minimum, which was computed to four decimal places. The positive roots of my equation were also computed to four places. When multiplied by sqrt(2), they differ from the user436560 results by at most 0.5% (average ratio 1.418). – Carl Lumma Feb 1 '19 at 21:42

Assuming the policy of replacing every P years, your total expenditure for the k'th P-year period is: $$M_0R^{kP}+U_0PR^{kP}$$ so the total for all P-year periods is the sum of this for all k: $$\frac{M_0+U_0P}{1-R^P}$$ To find the minimum over P, "brute force" is probably easiest. Or (for a rough answer) you could use your trick of equating the result for $P$ and $P-1$ using this formula which is not the same as yours and doesn't seem to come out nicely. Or you could differentiate it, but this gives a more complicated formula, so brute force seems easiest.