Ḣ_Ḣ×$÷’Ċ»0
Try it online!
Explanation
This uses the same formula as my Python answer: \$X\geq\frac{W-PN}{P-1}\$
Takes the input as a list of three numbers, \$W,N,P\$.
Ḣ_Ḣ×$÷’Ċ»0 Main Link
Ḣ W (pops from the list)
_ minus
Ḣ×$ N (pops from the list) times the list (now only has P)
÷’ divided by (P - 1)
Ċ ceiling
»0 maximum of that and 0
In-depth explanation
This is an even more in-depth explanation of this answer. If you are familiar with Jelly, you should probably skip this. I won't do these often.
Since this link is called with one argument each time, it is a monadic chain. Hence, as we walk down the chain, the following patterns are matched in this order: dyad-monad
, dyad-nilad
, nilad-dyad
, dyad
, and monad
(nilads take 0 arguments; you can think of them as constants) (monads take 1 argument) (dyads take 2 arguments).
Since the link doesn't start with a nilad, the evaluation value starts equal to the argument, [W, N, P]
.
First, we see Ḣ
, a monad meaning "pop and return the first element". This matches the last rule, so it applies as a monad to the current value, which is [W, N, P]
. Thus, the current value is now W
, and this also modifies the left argument object itself to [N, P]
.
Here, it is important to note the function of $
- it takes the last two links and groups them into a monadic link. Here, the two links are Ḣ
and ×
. We'll get back to this.
Next, we see _
, a dyad (subtraction). It is followed by a monad, namely the one formed by the $
grouping two links, thus matching the first pattern. The dyad-monad pattern, if we have some dyad +
and some monad F
, computes v + F(a)
where v
is the current value and a
is the right argument. Thus, this computes W - F([N, P])
. Here, F(a)
computes Ḣ×
as a monadic chain whose argument is a = [N, P]
. The value starts at v = [N, P]
as well.
The first link is a monad and thus the value becomes N
. Also, since "pop" mutates, the argument (to both the sub-link and the main link) is now [P]
. Then, the second link is a dyad and nothing else follows, so the value becomes N × [P]
which is [NP]
. This is a singleton list, not a value, but that's fine because everything else vectorizes.
Now, the value is W - [NP]
which vectorizes to [W - NP]
, and the argumnt is [P]
since it was mutated within the sub-link.
÷’
is a dyad-monad chain, which computes [W - NP] ÷ P÷’
. ’
decrements, so this computes [W - NP] ÷ (P - 1)
, which vectorizes to [(W - NP) / (P - 1)]
.
Penultimately, Ċ
is a monad meaning "ceiling", which just rounds all of these values up. Finally, »0
is a dyad-nilad chain which takes the maximum of this value and 0, thus preventing negative outputs.
Here's a shitty hand-drawn visualization of how chaining works out here:
