(Throughout this answer I use $\phi = \frac{1+\sqrt{5}}{2}$, which is the Golden Ratio.)
Solution:
- If $s\leq n$, the attackers can win in one day.
- If $s+dpw<\phi^2n$ and $s<2n$, the attackers can win in $2+\max(k,0)$ days, where
$$k=\left\lceil\frac{\log_\phi{\left(\frac{n+(dpw+s-2n)\phi^{-1}}{n-(dpw+s-2n)\phi}\right)}}{4}\right\rceil.$$
- If $dpw<n$, the attackers can win in $c+\max(k,0)$ days, where
$$c = \left\lceil\frac{\sqrt{dpw^2+4 n\cdot dpw}-dpw+2 n-2 s}{2 (dpw-n)}\right\rceil$$
and
$$k = \left\lceil\frac{\log_\phi{\left(\frac{n+(s + c\cdot dpw-(c+1)n)\phi^{-1}}{n-(s + c\cdot dpw-(c+1)n)\phi}\right)}}{4}\right\rceil.$$
- If the attackers cannot win, the minimum number of days for the castle to win is $2$ (the attackers all fire their cannons and are wiped out on day two).
Proof:
For a given day $i$, let $s_i$ be the remaining castle strength, $a_i$ be the remaining attacking force, and $d_i$ be the remaining defending force.
First consider the case that $d_i = dpw$ (that is, the attackers killed all defenders the day before). Assume that the attackers leave $x$ defenders alive but do not destroy the castle; then
$$a_{i+1} = a_i-x;$$
$$d_{i+1} = dpw+x;$$
$$s_{i+1} = s_i-(a_i-(dpw-x)) = (s_i+dpw)-(a_i+x).$$
On day $i+1$, the defending force is larger than on day $i$ and the attacking force is smaller than on day $i$. Furthermore, even if the attackers return to the strategy of wiping out the defending force on day $i+1$,
$$a_{i+2} = a_i-x;$$
$$d_{i+2} = dpw;$$
$$s_{i+2} = s_{i+1}-(a_{i+1}-d_{i+1}) = s_i+2dpw+x-2a_i.$$
If, instead, the attackers had wiped the defending force on day $i$, the castle's strength would be $s_i+2dpw-2a_i$. Therefore, it is never advantageous to leave both defenders and the castle alive on the same day.
(Note that if $s_i+2dpw+x-2a_i<0$ -- that is, they destroyed the castle on day $i+1$ -- they could have have done the same thing without losing troops; therefore, while it might not always be disadvantageous, it is never advantageous.)
Now the question is, when the attackers do destroy the castle, how many days will it take to kill the remaining defenders (with the obvious assumption that the attackers would not make a final push on the castle unless they can still win)? Assume, without loss of generality, that the castle is destroyed on day $q$ and that there are $x$ defenders remaining alive. So
$$d_{q+1} = x;$$
$$a_{q+1} = n-x;$$
$$d_{q+2} = d_{q+1}-a_{q+1} = 2x-n;$$
$$a_{q+2} = a_{q+1}-d_{q+2} = 2n-3x;$$
$$d_{q+3} = d_{q+2}-a_{q+2} = 5x-3n;$$
$$\dots$$
From this we can see that $d_{q+i+1} = Fib(2i+1)x-Fib(2i)n$. Therefore, (finding the closed form of $Fib(\cdot)$ and four pages of algebra later), the attackers will win
$$k = \left\lceil\frac{\log_\phi{\left(\frac{n+x\phi^{-1}}{n-x\phi}\right)}}{4}\right\rceil$$
days after destroying the castle. $x = s'+dpw-n$, where $s'$ is the strength of the castle on the day it is destroyed.
On every day that the attackers can make a final push on the castle, the question is, "Would it be advantageous to wait until tomorrow?" Every day (after the first) that the attackers do not make a final push, the castle's strength decreases by $n-dpw$. Therefore, at the beginning of the day of the final push (day $i$), $s' = s-n-(i-1)(n-dpw)$, so $x_i = dpw-(n-s') = $ $s + i\cdot dpw-(i+1)n$ (where $x_i$ is the remaining defending force if the attackers pushed on day $i$). It is advantageous to wait another day if
$$
\frac{\log_\phi{\left(\frac{n+x_{i+1}\phi^{-1}}{n-x_{i+1}\phi}\right)}}{4} + 1
<
\frac{\log_\phi{\left(\frac{n+x_i\phi^{-1}}{n-x_i\phi}\right)}}{4},$$
that is, when one more than the number of days to destroy the $x$ beginning on day $i+1$ is less than the number of days to destroy $x$ beginning on day $i$. Three pages of algebra later, we find that it becomes advantageous to destroy the castle on the day
$$c = \left\lceil\frac{\sqrt{dpw^2+4 n\cdot dpw}-dpw+2 n-2 s}{2 (dpw-n)}\right\rceil.$$
After destroying the castle, we still have to kill the troops, so the total number of days is $c+k$, using $i=c$ to find $k$.
Finally, we must handle the edge case that $dpw \geq n$. Intuitively, the attackers can only be victorious only if they can destroy the castle on the first day of fighting (day 2) with enough troops left to defeat the remaining defenders. This can only happen if $s<2n$ (they can destroy the castle by the end of the second day) and if $s+dpw<(\phi+1)n$ (they can destroy the castle and do enough damage that the defenders cannot effectively retaliate); it will take $\left\lceil\frac{\log_\phi{\left(\frac{n+(dpw+s-2n)\phi^{-1}}{n-(dpw+s-2n)\phi}\right)}}{4}\right\rceil$ days to kill the rest of the defenders.
dpw
constant, no re-inforcements?) For the attacker, it seems detrimental to have any killed -n
<=dpw
: molest a castle with weaker defence; else wipe the defenders and use what remains in firing power to break down the castle. $\endgroup$ – greybeard Jul 30 '15 at 15:20n<dpw
is when it is okay to make the final push on the castle. $\endgroup$ – Kittsil Jul 30 '15 at 19:54